N=10**8 S=int(input()) for i in range(S): ans=0 a,b=map(int,input().split()) ans+=N//b if a%2==0: ans+=2 print(ans)