from fractions import gcd
mod = 1000000007
t = int(raw_input())
while t:
a,b = map(int,raw_input().split())
if ( gcd(a,b)==1 ):
print (a*b - a - b)%mod
else:
print 'infinite solutions'
t-=1
ZnJvbSBmcmFjdGlvbnMgaW1wb3J0IGdjZCAKCm1vZCA9IDEwMDAwMDAwMDcKdCA9IGludChyYXdfaW5wdXQoKSkKd2hpbGUgdDoKCWEsYiA9IG1hcChpbnQscmF3X2lucHV0KCkuc3BsaXQoKSkKCWlmICggZ2NkKGEsYik9PTEgKToKCQlwcmludCAoYSpiIC0gYSAtIGIpJW1vZAoJZWxzZToKCQlwcmludCAnaW5maW5pdGUgc29sdXRpb25zJwoJCgl0LT0x