import math Q=int(input()) for _ in range(Q): D,K=map(int,input().split()) P=[] if D==0:P.append((0,0)) else: for x in range(1,D+1): P.append((x,D-x)) E=[] for x,y in P: E.append((math.sqrt(x**2+y**2),(x,y))) E.sort() if (len(E)==1 and K==1) or (len(E)>1 and K//4