# we start by choosing door d, let Monty open a door,
# and then we switch to the smallest-numbered unopened door
# when do we win?
# - if the prize is in door 1
# - if the prize is in door 2 and Monty opens door 1 for us
tests = int( input() )
for test in range(tests):
input()
tokens = input().split()
doors, prob = int( tokens[0] ), float( tokens[1] )
answer = 1/doors + (1/doors) * (prob + (1-prob)*(1/(doors-2)))
print('{:.20f}'.format(answer))