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