n=int(input())
a=[0 for i in range(n)]
b=[0 for i in range(n)]
c=[0 for i in range(n)]
for i in range(n):
    a[i],b[i]=[int(i) for i in input().split()]
    c[i]=a[i]*b[i]
#print(a,b)

def keisan(d,e,f):
    count=0
    old_value=10**20
    for j in range(int(d)):
        value=min(old_value,int((d-1)/(j+1)))

#        print(value)

        if old_value==value:
            value-=1

        if value>0:
            if e!=j+1 and f!=value:
                count+=1
                old_value=value
            elif e==j+1:
               pass
            elif f==value:
               pass
        else:
            break
    print(count)

for i in range(n):        
    keisan(c[i],a[i],b[i])
