def solve1(doors,prob,first):
# generate all possible scenarios
P = [ [ 0. for prize in range(doors+1) ] for opened in range(doors+1) ]
# the prize can be behind any door
for prize in range(1,doors+1):
pp = 1./doors
# the door selected to be opened can be any door other than {prize,first}
for opened in range(1,doors+1):
if prize == opened: continue
if first == opened: continue
candidate_doors = doors-1 if prize==first else doors-2
po = 1./candidate_doors
# now Monty either actually opens the door, or opens the smallest door he can
P[opened][prize] += pp * po * (1 - prob)
lazy = 1
if lazy == first or lazy == prize: lazy += 1
if lazy == first or lazy == prize: lazy += 1
P[lazy][prize] += pp * po * prob
answer = 0.
for opened in range(1,doors+1):
if first == opened: continue
best = max( P[opened][prize] for prize in range(1,doors+1) )
# print('If first={} and opened={}: best door {} gives {:.12f}.'.format(first,opened,P[opened].index(best),best))
answer += best
return answer
def solve(doors,prob):
# try all possibilities for which door to choose first; pick best one
best = 0.
for first in range(1,doors+1):
curr = solve1(doors,prob,first)
# print('Choosing door {} gives winprob {:.12f}'.format(first,curr))
best = max(curr,best)
print('{:.20f}'.format(best))
tests = int( input() )
for test in range(tests):
input()
tokens = input().split()
doors = int( tokens[0] )
prob = float( tokens[1] )
solve(doors,prob)