for cas in xrange(input()): m, p = map(float, raw_input().strip().split()) ans = 1e9 * (1 - (-p)**m) / (1 + p) print "%.11lf %.11lf" % (ans, 1e9 - ans)