Consider the set of all nonnegative integers: ${0, 1, 2, \dots}$. Given two integers $a$ and $b$ ($1 \le a, b \le 10^4$). We paint all the numbers in increasing number first we paint $0$, then we paint $1$, then $2$ and so on.

Each number is painted white or black. We paint a number $i$ according to the following rules:   if $i = 0$, it is colored white;   if $i \ge a$ and $i - a$ is colored white, $i$ is also colored white;   if $i \ge b$ and $i - b$ is colored white, $i$ is also colored white;   if $i$ is still not colored white, it is colored black. 

In this way, each nonnegative integer gets one of two colors.

For example, if $a=3$, $b=5$, then the colors of the numbers (in the order from $0$) are: white ($0$), black ($1$), black ($2$), white ($3$), black ($4$), white ($5$), white ($6$), black ($7$), white ($8$), white ($9$), ...

Note that:   It is possible that there are infinitely many nonnegative integers colored black. For example, if $a = 10$ and $b = 10$, then only $0, 10, 20, 30$ and any other nonnegative integers that end in $0$ when written in base 10 are white. The other integers are colored black.   It is also possible that there are only finitely many nonnegative integers colored black. For example, when $a = 1$ and $b = 10$, then there is no nonnegative integer colored black at all. 

Your task is to determine whether or not the number of nonnegative integers colored black is infinite.

If there are infinitely many nonnegative integers colored black, simply print a line containing "Infinite" (without the quotes). Otherwise, print "Finite" (without the quotes).


-----Input-----

The first line of input contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then $t$ lines follow, each line contains two space-separated integers $a$ and $b$ ($1 \le a, b \le 10^4$).


-----Output-----

For each test case, print one line containing either "Infinite" or "Finite" (without the quotes). Output is case-insensitive (i.e. "infinite", "inFiNite" or "finiTE" are all valid answers).


-----Example-----
Input
4
10 10
1 10
6 9
7 3

Output
Infinite
Finite
Infinite
Finite

Difficulty: EASY
Tags: Number theory

Mathematics

Starter code:

Solutions:
import math
for nt in range(int(input())):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
from fractions import gcd
lines = sys.stdin.readlines()
t = int(lines[0])
for i in range(t):
	L = list(map(int, lines[i + 1].split()))
	if gcd(L[0], L[1]) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
t = int(input())

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def hello():
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('inFinite')
for i in range(t):
	hello()


def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
n = int(input())
for i in range(n):
	asdf = [int(x) for x in input().split(' ')]
	a = asdf[0]
	b = asdf[1]
	if computeGCD(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for t in range(int(input())):
	(x, y) = map(int, input().split())
	if gcd(x, y) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
T = int(input())
while T > 0:
	(a, b) = map(int, input().split())
	print('Infinite' if gcd(a, b) != 1 else 'Finite')
	T -= 1


def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x
T = int(input())
for _ in range(T):
	(a, b) = [int(x) for x in input().split()]
	if 1 in [a, b] or 1 == gcd(a, b):
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
import sys
from collections import defaultdict
rt = lambda : map(int, input().split())
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))

def solve(n, a):
	pass

def main():
	T = ri()
	for t in range(T):
		(a, b) = rt()
		g = math.gcd(a, b)
		print('infinite' if g > 1 else 'finite')
main()


import sys
import os
from io import BytesIO, IOBase

def cel(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import gcd
for _ in range(ii()):
	(a, b) = mi()
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


import math

def ans(a, b):
	if math.gcd(a, b) == 1:
		return 'finite'
	else:
		return 'infinite'
T = int(input())
for _ in range(T):
	(a, b) = input().split(' ')
	a = int(a)
	b = int(b)
	print(ans(a, b))


from collections import defaultdict as dc
from collections import deque as dq
from bisect import bisect_left, bisect_right, insort_left
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def bs(a, b):
	l = a
	r = b + 1
	x = b
	ans = 0
	while l < r:
		mid = (l + r) // 2
		if x | mid > ans:
			ans = x | mid
			l = mid + 1
		else:
			r = mid
	return ans

def digit(n):
	a = []
	while n > 0:
		a.append(n % 10)
		n = n // 10
	return a
for _ in range(int(inp())):
	(a, b) = line()
	c = math.gcd(a, b)
	if c == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split(' '))
	t -= 1
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
a = int(input())
no_of_lines = a
lines = ''
for i in range(a):
	lines += input() + '\n'
b = lines.split()
for i in range(0, a):
	x = int(b[2 * i])
	y = int(b[2 * i + 1])
	if math.gcd(x, y) == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
from math import *
while t > 0:
	t -= 1
	(a, b) = map(int, input().split())
	print('infinite' if gcd(a, b) != 1 else 'finite')


n = int(input())

def gcd(n, m):
	a = max(n, m)
	b = min(n, m)
	while b:
		(a, b) = (b, a % b)
	return a

def main():
	(a, b) = map(int, input().split())
	gcdnum = gcd(a, b)
	if gcdnum == 1:
		print('Finite')
	else:
		print('Infinite')
for i in range(n):
	main()


def gcd(a, b):
	if b == 0:
		return a
	elif a == 0:
		return b
	return gcd(b, a % b)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if a > b:
		(a, b) = (b, a)
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	if a == 0 or b == 0:
		return max(a, b)
	if a < b:
		return gcd(a, b % a)
	else:
		return gcd(b, a % b)
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


import sys
import math

def main():
	for _ in range(int(input())):
		(a, b) = [int(x) for x in sys.stdin.readline().split()]
		x = math.gcd(a, b)
		if x == 1:
			print('Finite')
		else:
			print('Infinite')
main()


n = int(input())
for i in range(n):
	c = 0
	(a, b) = [int(x) for x in input().split(' ')]
	if a == b and a != 1:
		print('Infinite')
	elif min(a, b) == 2 and max(a, b) % 2 == 0:
		print('Infinite')
	else:
		for j in range(2, min(a, b) + 1):
			if a % j == 0 and b % j == 0:
				print('Infinite')
				c = 1
				break
		if c == 0:
			print('Finite')


import math
T = int(input())
for t in range(T):
	(A, B) = map(int, input().split())
	if A == 1 or B == 1:
		print('Finite')
	elif math.gcd(A, B) != 1:
		print('Infinite')
	else:
		print('Finite')


from math import gcd
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('FiNiTe' if gcd(a, b) == 1 else 'INfiNIte')


import math

def gcd(a, b):
	return math.gcd(a, b)
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().split()]
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def mod(x, y):
	temp = x
	x = y
	y = temp % y
	return (x, y)
t = input()
for i in range(int(t)):
	k = input()
	found = False
	zer = False
	num1 = k.split(' ')
	num = []
	for j in range(len(num1)):
		num.append(int(num1[j]))
	for j in range(len(num)):
		if num[j] == 0 and num[1 - j] != 1:
			zer = True
			break
		elif num[j] == 0 and num[1 - j] == 1:
			found = True
			break
	if zer or found:
		break
	(a, b) = (num[0], num[1])
	while b != 0:
		if a == 1 or b == 1:
			found = True
			break
		t = mod(a, b)
		a = t[0]
		b = t[1]
	if not found:
		print('infinite')
	else:
		print('finite')


def gcd(a, b):
	return a if b == 0 else gcd(b, a % b)
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print('Finite' if gcd(a, b) == 1 else 'Infinite')


import math
import sys

def primeFactors(n):
	res = []
	while n % 2 == 0:
		res.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			res.append(i)
			n = n / i
	if n > 2:
		res.append(n)
	return res
t = int(input())
for _ in range(t):
	a_b = list(map(int, sys.stdin.readline().split()))
	a = a_b[0]
	b = a_b[1]
	p_a = set(primeFactors(a))
	p_b = set(primeFactors(b))
	inters = list(p_a & p_b)
	if inters:
		print('Infinite')
	else:
		print('Finite')


import sys
from fractions import gcd
cin = sys.stdin.buffer.readline
for _ in range(int(cin())):
	(a, b) = map(int, cin().split())
	print(['finite', 'infinite'][gcd(a, b) != 1])


n = int(input())
ans = []
for i in range(n):
	k = input()
	a = int(k.split()[0])
	b = int(k.split()[1])
	m = 1
	for j in range(2, min(a, b) + 1):
		if a % j == 0 and b % j == 0:
			m = 2
			ans.append('infinite')
			break
	if m == 1:
		ans.append('finite')
for el in ans:
	print(el)


import sys, math, statistics as ss, collections as cc
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')


n = int(input())
b = []
for i in range(n):
	b.append(list(map(int, input().split())))
for i in range(0, n):
	while b[i][1] > 0:
		(b[i][0], b[i][1]) = (b[i][1], b[i][0] % b[i][1])
	if b[i][0] != 1:
		print('Infinite')
	else:
		print('Finite')


def is_coprime(a, b):
	for n in range(2, a + 1):
		if a % n == b % n == 0:
			return False
	return True
num_inputs = int(input())
for _ in range(num_inputs):
	inputs = [int(n) for n in input().split()]
	if min(inputs) == 1 or is_coprime(*inputs):
		print('Finite')
	else:
		print('Infinite')


import math
nb_cases = int(input())
for case in range(nb_cases):
	(a, b) = [int(x) for x in input().split()]
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
import math
q = int(input())
for case in range(q):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math

def coprimes(a, b):
	if a == 1:
		return 0
	if b == 1:
		return 0
	if a == 2:
		if b % a == 0:
			return 1
	elif b == 2:
		if b % a == 0:
			return 1
	if a > b:
		if a % b == 0:
			return 1
	elif b % a == 0:
		return 1
	for i in range(2, int(math.sqrt(a)) + 1):
		if a % i == 0:
			if b % i == 0:
				return 1
			if b % int(a / i) == 0:
				return 1
	else:
		return 0

def printRES(a, b):
	if coprimes(a, b) == 1:
		print('INFINITE')
	else:
		print('FINITE')
t = int(input())
for i in range(t):
	(p, q) = map(int, input().split())
	printRES(p, q)


import os
import sys
from io import BytesIO, IOBase
from math import gcd

def solution(a, b):
	write('finite' if gcd(a, b) == 1 else 'infinite')

def main():
	for _ in range(r_int()):
		(a, b) = r_array()
		solution(a, b)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


import sys
input = sys.stdin.readline

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors

def main():
	t = int(input())
	for _ in range(t):
		(A, B) = [int(x) for x in input().split()]
		a_div = make_divisors(A)
		b_div = make_divisors(B)
		if A == 1 or B == 1:
			print('Finite')
			continue
		if len(set(a_div) & set(b_div)) > 1:
			print('Infinite')
			continue
		print('Finite')
main()


from fractions import gcd
t = int(input())
b = []
for a in range(t):
	(a, b) = map(int, input().split())
	num = gcd(a, b)
	if num == 1:
		print('Finite')
	else:
		print('Infinite')


import math
for _ in [0] * int(input()):
	print(' in'[:1 | math.gcd(*map(int, input().split()))] + 'finite')


from math import gcd
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	print('Finite' if gcd(x, y) == 1 else 'Infinite')


import math
for i in range(int(input())):
	(a, b) = map(int, input().split())
	print('Finite') if math.gcd(a, b) == 1 else print('infinite')


def computeHCF(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	h = computeHCF(a, b)
	if h == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
from math import gcd
for _t in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('FINITE')
	else:
		print('INFINITE')


def gcd(a, b):
	while b:
		rem = a % b
		a = b
		b = rem
	return a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


t = int(input())
a = []
for i in range(t):
	a.append([0] * 2)
for i in range(0, t):
	(a[i][0], a[i][1]) = map(int, input().split())
b = []
for i in range(0, t):
	f = a[i][0]
	g = a[i][1]
	while f != 0 and g != 0:
		if f > g:
			f = f % g
		else:
			g = g % f
	b.append(f + g)
for i in range(0, t):
	if b[i] == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
d = [0 for i in range(10000)]
for i in range(t):
	(a, b) = map(int, input().split())
	while b != 0:
		c = a
		a = b
		b = c % b
	if a == 1:
		print('finite')
	else:
		print('infinite')


import math

def solve():
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')
	return
t = int(input())
while t:
	solve()
	t -= 1


import math
t = int(input())
for q in range(t):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('FINITE')
	else:
		print('infinite')


from collections import defaultdict as df
import bisect
from sys import stdin, stdout
import math
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def solve():
	(a, b) = sorted(num_input())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')
t = int(input())
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('InFinite')


import sys, math
tc = int(sys.stdin.readline())
for _ in range(tc):
	(a, b) = map(int, sys.stdin.readline().split())
	if math.gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


from math import *
t = int(input())

def cp(a, b):
	if gcd(a, b) == 1:
		return True
	else:
		return False
zzz = []
for z in range(t):
	(a, b) = [int(i) for i in input().split()]
	zzz.append(cp(a, b))
for i in zzz:
	print('Finite' if i else 'Infinite')


a = int(input())

def lcd(a, b):
	for i in range(2, min(b, a) + 1):
		if a % i == 0 and b % i == 0:
			return True
	return False
for i in range(a):
	b = list(map(int, input().strip().split(' ')))
	if b[0] == 1 or b[1] == 1:
		print('Finite')
	elif lcd(b[1], b[0]):
		print('Infinite')
	else:
		print('Finite')


t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	import math
	if math.gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


from math import gcd
t = int(input())
while t:
	(a, b) = map(int, input().split())
	ans = abs(b - a)
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')
	t -= 1


from math import gcd

def solve(ls):
	for i in range(len(ls)):
		x = gcd(ls[i][0], ls[i][1])
		if x != 1:
			print('Infinite')
		else:
			print('Finite')
	return None

def main():
	n = int(input())
	ls = []
	for i in range(n):
		ls.append(list(map(int, input().split())))
	solve(ls)
main()


def gcd(a, b):
	while b != 0:
		a = a % b
		(a, b) = (b, a)
	return a

def solve():
	n = int(input())
	for i in range(n):
		(a, b) = list(map(int, input().split()))
		if gcd(a, b) == 1:
			print('Finite')
		else:
			print('Infinite')
solve()


def hcf(a, b):
	if b == 1:
		return 1
	elif b == 0:
		return a
	else:
		return hcf(b, a % b)
q = int(input())
inputlist = []
for j in range(q):
	inputlist.append(list(map(int, input().split())))
for j in inputlist:
	if hcf(j[0], j[1]) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd as bltin_gcd

def coprime2(a, b):
	return bltin_gcd(a, b) == 1
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a == 1 or b == 1:
		print('Finite')
		continue
	elif coprime2(a, b):
		print('Finite')
	else:
		print('Infinite')


def compute_hcf(x, y):
	if x > y:
		smaller = y
	else:
		smaller = x
	for i in range(1, smaller + 1):
		if x % i == 0 and y % i == 0:
			hcf = i
	return hcf

def program():
	(a, b) = map(int, input().split())
	if a == 1 or b == 1:
		print('Finite')
		return 0
	if abs(a - b) == 1:
		print('Finite')
		return 0
	h = compute_hcf(a, b)
	if h == 1:
		print('Finite')
	else:
		print('Infinite')
t = int(input())
for i in range(t):
	program()


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
import math
import bisect
t = ii()
for i in range(t):
	(a, b) = mi()
	if math.gcd(a, b) == 1:
		print('FINITE')
	else:
		print('INFINITE')


def fun(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
n = int(input())
for i in range(n):
	(s, d) = [int(x) for x in input().split()]
	if fun(s, d) != 1:
		print('Infinite')
	else:
		print('Finite')


import sys

def readFile():
	data = []
	with open('../input.txt') as file:
		for line in file.readlines():
			data.append(line.strip('\n'))
	return data

def readStdin():
	data = []
	for line in sys.stdin.readlines():
		data.append(line.strip('\n'))
	return data

def nod(a, b):
	if a % b == 0:
		return b
	if b % a == 0:
		return a
	return nod(a % b, b) if a > b else nod(a, b % a)
data = readStdin()
n = int(data[0]) + 1
for i in range(1, n):
	(a, b) = (int(data[i].split(' ')[0]), int(data[i].split(' ')[1]))
	c = nod(a, b)
	if c == 1:
		print('Finite')
	else:
		print('Infinite')


def eu(a, b):
	if min(a, b) == 0:
		return max(a, b)
	(a, b) = (min(a, b), max(a, b) % min(a, b))
	return eu(a, b)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if eu(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from collections import defaultdict as dd
from math import gcd
(t,) = I()
while t:
	t -= 1
	(a, b) = I()
	ans = 'Infinite'
	if gcd(a, b) == 1:
		ans = 'Finite'
	print(ans)


def nod(a, b):
	while a > 1 and b > 1:
		if a > b:
			a = a % b
		else:
			b = b % a
	if a == 0:
		return b
	if b == 0:
		return a
	return 1
q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	if nod(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
q = int(input())
for i in range(q):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


import sys
input = sys.stdin.readline
import math
t = int(input())
for test in range(t):
	(a, b) = list(map(int, input().split()))
	k = math.gcd(a, b)
	if k != 1:
		print('Infinite')
	else:
		print('Finite')


n = int(input())

def gcd(a, b):
	r = a % b
	while r != 0:
		a = b
		b = r
		r = a % b
	return b
for i in range(n):
	row_data = input()
	row_data = row_data.split(' ')
	a = int(row_data[0])
	b = int(row_data[1])
	an = max(a, b)
	bn = min(a, b)
	if bn == 1:
		print('Finite')
	elif gcd(an, bn) != 1:
		print('Infinite')
	else:
		print('Finite')


def gcd(a, b):
	while a and b:
		if a >= b:
			a %= b
		else:
			b %= a
	return a | b
t = int(input())
for i in range(t):
	(a, b) = [int(s) for s in input().split()]
	if min(a, b) == 1:
		print('Finite')
		continue
	elif gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


import math
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if math.gcd(n, m) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
for q in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def has_common_divisor(a, b):
	for i in range(2, min(a, b) + 1):
		if a % i == b % i == 0:
			return True
	return False
for _ in range(int(input())):
	s = input().split()
	(a, b) = (int(s[0]), int(s[1]))
	print('Finite' if a == 1 or b == 1 else 'Infinite' if has_common_divisor(a, b) else 'Finite')


from math import gcd
for i in range(int(input())):
	X = list(map(int, input().split()))
	print('Finite' if gcd(X[0], X[1]) == 1 else 'Infinite')


import math
cases = int(input())
for _ in range(cases):
	(a, b) = map(int, input().split())
	x = math.gcd(a, b)
	if x != 1:
		print('infinite')
	else:
		print('finite')


t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	(low, high) = (min(a, b), max(a, b))
	rem = list(range(low))
	rem1 = []
	for i in range(1, low + 1):
		rem1.append(high * i % low)
	if set(rem1) == set(rem):
		print('Finite')
	else:
		print('Infinite')


import math
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if math.gcd(x, y) != 1:
		print('INFINITE')
	else:
		print('FINITE')


import math
for _ in range(int(input())):
	s = input().split()
	a = int(s[0])
	b = int(s[1])
	if math.gcd(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m1 = min(a, b)
	max1 = 0
	for i in range(2, a + 1):
		if a % i == 0:
			if b % i == 0:
				if max1 < i:
					max1 = i
	if max1 == 0:
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return a + b
q = int(input())
for i in range(q):
	(a, b) = [int(i) for i in input().split()]
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(m, n):
	if not isinstance(m, int) or not isinstance(n, int):
		raise TypeError
	if n == 0:
		(m, n) = (n, m)
	while m:
		(m, n) = (n % m, m)
	return n
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split(' ')))
	x = gcd(a, b)
	if x > 1:
		print('Infinite')
	else:
		print('Finite')


import math
for i in int(input()) * [0]:
	(a, b) = sorted(map(int, input().split()))
	print('finite' if math.gcd(a, b) == 1 else 'infinite')


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def solve(a, b):
	if gcd(a, b) == 1:
		return 'Finite'
	else:
		return 'Infinite'
q = int(input())
for i in range(q):
	line = input()
	a = int(line.split()[0])
	b = int(line.split()[1])
	res = solve(a, b)
	print(res)


from math import gcd
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	print('Infinite' if gcd(a, b) > 1 else 'Finite')


def div(a, b):
	k = 2
	while k <= max(a, b):
		if a % k == 0 and b % k == 0:
			return 1
		k += 1
	return 0
n = int(input())
for i in range(n):
	entrada = input().split(' ')
	if div(int(entrada[0]), int(entrada[1])) == 0:
		print('Finite')
	else:
		print('Infinite')


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(a, b) = sep()
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')
testcase(int(inp()))


import math
n = int(input())
lst2 = []
for i in range(n):
	lst1 = list(map(int, input().split()))
	if math.gcd(lst1[0], lst1[1]) == 1:
		lst2.append('Finite')
	else:
		lst2.append('Infinite')
for i in lst2:
	print(i)


t = int(input())
for i in range(0, t):
	(a, b) = map(int, input().split())
	while a % b != 0:
		t = b
		b = a % b
		a = t
	print('Infinite' if b > 1 else 'Finite')


from math import gcd

def A():
	answer = ''
	for i in range(int(input())):
		(a, b) = map(int, input().split(' '))
		if gcd(a, b) == 1:
			answer += 'Finite \n'
		else:
			answer += 'Infinite \n'
	print(answer)
A()


from sys import stdin
import math
for _ in range(int(input())):
	(n, m) = map(int, stdin.readline().rstrip().split(' '))
	if math.gcd(n, m) != 1:
		print('Infinite')
	else:
		print('Finite')


def evk(a, b):
	while a != 0 and b != 0:
		while a >= b and a != 0 and (b != 0):
			a -= b
		while b >= a and a != 0 and (b != 0):
			b -= a
	if a == 0:
		return b
	else:
		return a
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if evk(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
import itertools
import math
import collections
from collections import Counter

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def ceil(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
t = ii()
for _ in range(t):
	(n, m) = mi()
	print('Finite') if math.gcd(n, m) == 1 else print('Infinite')


t = int(input())
inpList = []
outList = []

def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def coprime(a, b):
	return gcd(a, b) == 1
for i in range(t):
	inpList.append(input().split(' '))
	tLst = inpList.pop(0)
	a = int(tLst[0])
	b = int(tLst[1])
	if a == 1 or b == 1:
		outList.append('finite')
	elif coprime(a, b) == False:
		outList.append('infinite')
	else:
		outList.append('finite')
for x in range(len(outList)):
	print(outList[x])


import re
n = int(input())
for i in range(n):
	ab = input()
	arr = re.sub('[^\\w]', '  ', ab).split()
	a = int(arr[0])
	b = int(arr[1])
	while b:
		(a, b) = (b, a % b)
	if a == 1:
		print('Finite')
	else:
		print('Infinite')


n = int(input())
i = 0
while i != n:
	(a, b) = map(int, input().split())
	while b != 0:
		(a, b) = (b, a % b)
	if a > 1:
		print('infinite')
	else:
		print('finite')
	i += 1


def nod(a, b):
	if a == 0 or b == 0:
		return max(a, b)
	if a == 1 or b == 1:
		return 1
	return nod(b % a, a)
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if nod(min(a, b), max(a, b)) == 1:
		print('Finite')
	else:
		print('Infinite')


def computeHCF(x, y):
	if x > y:
		smaller = y
	else:
		smaller = x
	for i in range(1, smaller + 1):
		if x % i == 0 and y % i == 0:
			hcf = i
	return hcf
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if computeHCF(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
from math import gcd
for line in sys.stdin:
	values = list(map(int, line.split()))
	if len(values) < 2:
		continue
	(a, b) = values
	g = gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


for i in range(int(input())):
	(X, Check) = (list(map(int, input().split())), True)
	for j in range(2, min(X) + 1):
		if X[0] % j == 0 and X[1] % j == 0:
			Check = False
			break
	print('Infinite' if not Check else 'Finite')


def eu(x, y):
	if x % y == 0:
		return y
	elif y % x == 0:
		return x
	elif x > y:
		return eu(x % y, y)
	else:
		return eu(x, y % x)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if eu(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def NOD(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	elif a > b:
		return NOD(a % b, b)
	return NOD(a, b % a)
k = int(input())
for i in range(k):
	(a, b) = map(int, input().split())
	temp = NOD(a, b)
	if temp == 1:
		print('Finite')
	else:
		print('infinite')


def main():
	from math import gcd
	T = int(input())
	for t in range(T):
		(a, b) = map(int, input().split())
		if gcd(a, b) == 1:
			print('Finite')
		else:
			print('Infinite')
main()


n = int(input())
for i in range(n):
	(r, s) = map(int, input().split())
	c = 0
	if r == s:
		c += 1
		t = 0
	elif r >= s:
		t = r
	elif s > r:
		t = s
	for i in range(2, t // 2 + 1):
		if r % i == 0 and s % i == 0:
			c += 1
			break
	if r == 1 or s == 1:
		print('Finite')
	elif c > 0:
		print('Infinite')
	else:
		print('Finite')


from sys import stdin, stdout
from collections import Counter

def ai():
	return list(map(int, stdin.readline().split()))

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
t = ip()
for i in range(t):
	(a, b) = ei()
	ans = gcd(a, b)
	print('Finite' if ans == 1 else 'Infinite')


from sys import stdin
from math import gcd

def cop(a, b):
	return gcd(a, b) == 1
for _ in range(int(stdin.readline())):
	if cop(*map(int, stdin.readline().split())):
		print('Finite')
	else:
		print('Infinite')


from math import gcd
for __ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from collections import Counter
from math import gcd

def run_testcase():
	[a, b] = [int(x) for x in input().split()]
	return 'Finite' if gcd(a, b) == 1 else 'Infinite'
testcase_count = int(input())
for i in range(testcase_count):
	print(str(run_testcase()))


import sys, math, statistics as ss, collections as cc

def main():
	n = int(input())
	for i in range(n):
		(a, b) = map(int, input().split())
		if math.gcd(a, b) > 1:
			print('Infinite')
		else:
			print('Finite')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


q = int(input())

def gcd(x, y):
	r = x % y
	if r == 0:
		return y
	else:
		while not r == 0:
			r = x % y
			x = y
			y = r
	return x
for i in range(q):
	[a, b] = list(map(int, input().split()))
	x = max(a, b)
	y = min(a, b)
	g = gcd(x, y)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
t = int(input())
for _ in range(t):
	(a, b) = [int(x) for x in input().strip().split(' ')]
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def nod(a, b):
	(a, b) = (min(a, b), max(a, b))
	while a > 0:
		(a, b) = (b % a, a)
	return b
t = int(input())
for i in range(t):
	(a, b) = [int(i) for i in input().split()]
	if nod(a, b) == 1:
		print('finite')
	else:
		print('infinite')


from math import gcd as g
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if g(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
import collections
import heapq
input = sys.stdin.readline

def rints():
	return map(int, input().strip().split())

def rstr():
	return input().strip()

def rint():
	return int(input().strip())

def rintas():
	return [int(i) for i in input().strip().split()]

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = rint()
for _ in range(t):
	(a, b) = rints()
	if a < b:
		(a, b) = (b, a)
	if a == 1 or b == 1:
		print('Finite')
		continue
	elif a == b:
		print('Infinite')
		continue
	c = gcd(a, b)
	if c == 1:
		print('Finite')
	else:
		print('Infinite')


def inp():
	return map(int, input().split())

def arr_inp():
	return [int(x) for x in input().split()]

def print_arr(arr):
	print(*arr, sep=' ')
import math
t = int(input())
for i in range(t):
	(a, b) = inp()
	if math.gcd(a, b) != 1:
		print('infinite')
	else:
		print('finite')


import math
t = int(input())
for i in range(t):
	(a, b) = [int(x) for x in input().split()]
	if a != 1 and b != 1:
		if math.gcd(a, b) == 1:
			print('finite')
		else:
			print('infinite')
	else:
		print('finite')


def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	elif a >= b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)
t = int(input())
for i in range(t):
	(a, b) = input().strip().split(' ')
	(a, b) = [int(a), int(b)]
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, sys.stdin.readline().split()))

def num():
	return map(int, sys.stdin.readline().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007

def solve():
	t = nu()
	for tt in range(t):
		(a, b) = num()
		if find_gcd(a, b) == 1:
			print('Finite')
		else:
			print('Infinite')
solve()


def inp(type):
	return type(input())

def minput(type):
	return map(type, input().split())

def linput(type):
	return list(minput(type))

def check(map, elem):
	if not map.__contains__(elem):
		map[elem] = set()
for _ in range(inp(int)):
	(a, b) = minput(int)
	if a < b:
		(a, b) = (b, a)
	l = [a, b]
	while l[len(l) - 1] != 0:
		l.append(l[len(l) - 2] % l[len(l) - 1])
	print('finite' if l[len(l) - 2] == 1 else 'infinite')


from collections import defaultdict
import math

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	if gcd(n, m) == 1:
		print('finite')
	else:
		print('infinite')


import math

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m = max(a, b)
	n = min(a, b)
	if a == 1 or b == 1:
		print('Finite')
	else:
		f = 0
		l1 = primeFactors(a)
		l2 = primeFactors(b)
		for x in l1:
			if x in l2:
				f = 1
				break
		if f == 0:
			print('Finite')
		else:
			print('Infinite')


import math
n = int(input())
m = 10000
j = 2
arr = []
while j < 10000:
	ok = True
	for z in range(2, int(math.sqrt(j)) + 1):
		if j % z == 0:
			ok = False
			break
	if ok:
		arr.append(j)
	j += 1
for i in range(n):
	(a, b) = map(int, input().split())
	fin = True
	for c in range(arr.__len__()):
		if a % arr[c] == 0 and b % arr[c] == 0:
			fin = False
			break
		if arr[c] > a or arr[c] > b:
			break
	if fin:
		print('Finite')
	else:
		print('Infinite')


from __future__ import print_function
import sys
import math
DEBUG = '-d' in sys.argv

def debug(*args, **kwargs):
	if DEBUG:
		print(*args, file=sys.stderr, **kwargs)
	return None
t = int(input().strip())
lst = []
for pos in range(t):
	lst += [list(map(int, input().strip().split(' ')))]
for case in range(len(lst)):
	(a, b) = (lst[case][0], lst[case][1])
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
while t:
	(a, b) = map(int, input().split())
	if a == 1 or b == 1:
		print('Finite')
	elif gcd(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 1 or b == 1:
		print('Finite')
	else:
		while b:
			(a, b) = (b, a % b)
		if a > 1:
			print('Infinite')
		else:
			print('Finite')


t = int(input())

def gcd(a, b):
	if not b:
		return a
	else:
		return gcd(b, a % b)
for i in range(t):
	(a, b) = (int(i) for i in input().split())
	if b < a:
		(a, b) = (b, a)
	g = gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if a == b and a != 1:
		print('infinite')
		continue
	if a > b:
		(a, b) = (b, a)
	z = b % a
	c = set()
	c.add(0)
	c_right = set()
	for j in range(1, a + 1):
		c_right.add(j - 1)
		if z * j % a not in c:
			c.add(z * j % a)
	if c_right == c:
		print('finite')
	else:
		print('infinite')


import math
for i in range(int(input())):
	arr = [int(i) for i in input().split()]
	if math.gcd(arr[0], arr[1]) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
n = int(input())
for i in range(n):
	(a, b) = [int(j) for j in input().split()]
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
import math
t = int(sys.stdin.readline())
for _ in range(t):
	(a, b) = (int(x) for x in sys.stdin.readline().split())
	result = 'Finite' if math.gcd(a, b) == 1 else 'Infinite'
	sys.stdout.write(result + '\n')


from sys import stdin
import math
t = int(stdin.readline())
while t:
	(a, b) = map(int, stdin.readline().split())
	if math.gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')
	t -= 1


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
tcs = int(input())
for _ in range(tcs):
	(a, b) = map(int, input().split())
	ret = gcd(a, b)
	if ret == 1:
		print('Finite')
	else:
		print('Infinite')


import math
a = int(input())
ones = []
twos = []
for i in range(a):
	(one, two) = input().split()
	ones.append(int(one))
	twos.append(int(two))
for i in range(len(ones)):
	if math.gcd(ones[i], twos[i]) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
n = int(input())
for i in range(n):
	(x, y) = input().split(' ')
	x = int(x)
	y = int(y)
	if math.gcd(x, y) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
for _ in range(int(input())):
	print(('IN' if gcd(*map(int, input().split())) > 1 else '') + 'FINITE')


def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a
for z in range(int(input())):
	(a, b) = map(int, input().split())
	if gcd(a, b) > 1:
		print('infinite')
	else:
		print('finite')


a = int(input())

def hcf(a, b):
	if b == 0:
		return a
	return hcf(b, a % b)
for i in range(0, a):
	(m, n) = map(int, input().split())
	if hcf(m, n) == 1:
		print('FINITE')
	else:
		print('INFINITE')


n = int(input())
for i in range(n):
	ab = input().split()
	a = int(ab[0])
	b = int(ab[1])
	if a > b:
		c = b
	else:
		c = a
	for i in range(1, c + 1):
		if a % i == 0 and b % i == 0:
			d = i
	if d == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	if gcd(a, b) == 1:
		print('Finite')
		continue
	print('Infinite')


import sys

def gcd(a, b):
	while b:
		a = a % b
		k = a
		m = b
		a = m
		b = k
	return a
t = int(input(''))
for i in range(t):
	mal = list(map(int, input().split()))
	if gcd(mal[0], mal[1]) == 1:
		print('Finite\n')
	else:
		print('Infinite')


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	while a != 1 and b != 1 and (a != 0) and (b != 0):
		if a > b:
			a = a % b
		else:
			b = b % a
	if min(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


testes = int(input())
for t in range(testes):
	ent = input().split(' ')
	a = int(ent[0])
	b = int(ent[1])
	maior = b
	if a >= b:
		maior = a
	cont = True
	for k in range(2, maior + 1):
		if a % k == 0 and b % k == 0:
			cont = False
			break
	if cont:
		print('Finite')
	else:
		print('Infinite')


from sys import stdin, stdout
from collections import *
from math import gcd, floor, ceil

def st():
	return list(stdin.readline().strip())

def li():
	return list(map(int, stdin.readline().split()))

def mp():
	return map(int, stdin.readline().split())

def inp():
	return int(stdin.readline())

def pr(n):
	return stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(a, b) = mp()
	pr('Finite' if gcd(a, b) == 1 else 'Infinite')
for _ in range(inp()):
	solve()


def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)
for iter in range(int(input())):
	(a, b) = map(int, input().split())
	if a == 1 or b == 1:
		print('Finite')
		continue
	elif a == b:
		print('Infinite')
		continue
	elif abs(a - b) == 1:
		print('Finite')
	elif gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
readline = sys.stdin.readline
rdw = lambda : readline().rstrip()
rdws = lambda : readline().split()
rdwl = lambda : list(readline().split())
rdi = lambda : int(readline())
rdis = lambda : map(int, readline().split())
rdil = lambda : list(map(int, readline().split()))
rdilrows = lambda cnt: [rdil() for _ in range(cnt)]

def gcd(a, b):
	if a < b:
		return gcd(b, a)
	else:
		if b == 0:
			return a
		return gcd(b, a % b)

def solve():
	(a, b) = rdis()
	res = gcd(a, b)
	print('Finite' if res == 1 else 'Infinite')
tests = 1
tests = rdi()
for testnum in range(tests):
	solve()


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	g = hcfnaive(a, b)
	if g > 1 and (a != 1 and b != 1):
		print('infinite')
	else:
		print('finite')
	t -= 1


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math as mt
ts = int(input())
while ts > 0:
	(n, k) = map(int, input().split())
	g = mt.gcd(n, k)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')
	ts -= 1


def criba_eratostenes(n):
	multiplos = set()
	for i in range(2, n + 1):
		if i not in multiplos:
			multiplos.update(range(i * i, n + 1, i))
			yield i
p = list(criba_eratostenes(10000))
for i in range(int(input())):
	a = [int(n) for n in input().split()]
	print('Infinite' if len([True for n in p if a[0] / n == a[0] // n and a[1] / n == a[1] // n]) else 'Finite')


import math
t = int(input())
for z in range(t):
	(a, b) = [int(x) for x in input().split()]
	x = math.gcd(a, b)
	if x == 1:
		print('Finite')
	else:
		print('Infinite')


n = int(input(''))
for i in range(n):
	s = input()
	(a, b) = s.split(' ')
	a = int(a)
	b = int(b)
	while a != 0 and b != 0:
		if a > b:
			a = a % b
		else:
			b = b % a
	if a == 1 or b == 1:
		print('finite')
	else:
		print('infinite')


import math
queries = int(input())
for x in range(queries):
	num = input().split()
	num = (int(x) for x in num)
	(a, b) = num
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	g = gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	if x == 1 or y == 1:
		print('Finite')
	elif x == y:
		print('Infinite')
	else:
		for i in range(max(x, y)):
			if x >= y:
				x -= y
			else:
				y -= x
			if x == 1 or y == 1:
				print('Finite')
				break
			elif x - y == 0:
				print('Infinite')
				break


import math
t = int(input())
for _ in range(t):
	(n1, n2) = map(int, input().strip().split())
	if math.gcd(n1, n2) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
for _ in range(int(input())):
	print(('F', 'Inf')[math.gcd(*map(int, input().split())) > 1] + 'inite')


import math
t = int(input())
for case in range(t):
	(a, b) = [int(x) for x in input().split(' ')]
	if min(a, b) == 1 or math.gcd(a, b) == 1:
		ans = 'Finite'
	else:
		ans = 'Infinite'
	print(ans)


import math
for _ in range(int(input())):
	s = [int(x) for x in input().split()]
	(a, b) = (s[0], s[1])
	if math.gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
for (A, B) in AB:
	ok = True
	for n in range(2, max(A, B) + 1):
		if A % n == 0 and B % n == 0:
			ok = False
	if ok:
		print('Finite')
	else:
		print('Infinite')


def printDivisors(n):
	arr = []
	i = 2
	while i <= n:
		if n % i == 0:
			arr.append(i)
		i = i + 1
	return arr
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	m1 = printDivisors(a)
	m2 = printDivisors(b)
	f = 0
	for x in m1:
		if x in m2:
			f = 1
			break
	if f == 1:
		print('Infinite')
	else:
		print('Finite')


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
from math import gcd
t = rint()
for _ in range(t):
	(a, b) = rints()
	print('Finite' if gcd(a, b) == 1 else 'Infinite')


def finite_black(a, b):
	if a > b:
		smal = b
	else:
		smal = a
	for x in range(smal, 0, -1):
		if a % x == 0 and b % x == 0:
			div = x
			break
	if div == 1:
		return 'Finite'
	else:
		return 'Infinite'
t = int(input())
quer = []
for x in range(t):
	quer.append(list(map(int, input().split())))
for (a, b) in quer:
	print(finite_black(a, b))


import sys
input = sys.stdin.readline
import math
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('finite')
	else:
		print('Infinite')


import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(int(input())):
	(a, b) = list(map(int, input().rsplit()[:2]))
	if gcd(a, b) > 1:
		print('infinite')
	else:
		print('finite')


def gcd(x, y):
	while y != 0:
		(x, y) = (y, x % y)
	return x

def main():
	t = int(input())
	while t:
		t -= 1
		(a, b) = [int(i) for i in input().split(' ')]
		if gcd(a, b) == 1:
			print('Finite')
		else:
			print('Infinite')
main()


q = int(input())
for i in range(q):
	(a, b) = [int(s) for s in input().split()]
	if a == 1 or b == 1:
		print('Finite')
		continue
	n = max(a, b)
	nums = [1] * (n + 1)
	finite = 1
	isPrime = [1 for i in range(n + 1)]
	for i in range(2, n + 1):
		if isPrime[i]:
			if a % i == 0 and b % i == 0:
				finite = 0
				break
			for j in range(i, n + 1, i):
				isPrime[j] = 0
	if finite:
		print('Finite')
	else:
		print('Infinite')


t = int(input())

def division(a, b):
	for i in range(2, min(a, b) + 1):
		if a % i == 0 and b % i == 0:
			return False
	return True
for _ in range(t):
	(a, b) = map(int, input().split())
	if a == 1 or b == 1:
		print('Finite')
	elif division(a, b):
		print('Finite')
	else:
		print('Infinite')


mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
from sys import stdin, stdout
import bisect
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import collections
import math
import heapq
import random

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def main():
	n = inin()
	for _ in range(n):
		(j, k) = cin()
		x = math.gcd(j, k)
		x = math.gcd(x, j - k)
		if x != 1:
			print('Infinite')
		else:
			print('Finite')
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import sys
import math
input = lambda : sys.stdin.readline().rstrip()
for i in range(int(input())):
	(a, b) = map(int, input().split())
	ans = 'Finite'
	for i in range(2, min(a, b) + 1 + 1):
		if a % i == 0 and b % i == 0:
			ans = 'Infinite'
			break
	print(ans)


import math
nn = int(input())
for _ in range(nn):
	(j, k) = map(int, input().split())
	x = math.gcd(j, k)
	x = math.gcd(x, j - k)
	if x != 1:
		print('Infinite')
	else:
		print('Finite')


from math import gcd
for i in range(int(input())):
	(a, b) = map(int, input().split())
	a1 = min(a, b)
	b1 = max(a, b)
	if a1 == 1:
		print('Finite')
		continue
	if gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


import math as m
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if m.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	a = max(x, y)
	b = min(x, y)
	if gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


from math import *
n = int(input())
for i in range(n):
	(a, b) = (int(s) for s in input().split())
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
from itertools import accumulate as ac
mod = int(1000000000.0) + 7
mod = 998244353
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(a, b) = inp()
	if gcd(a, b) == 1:
		ans = 'Finite'
	else:
		ans = 'Infinite'
	out(ans)


import math
t = int(input())
for q in range(0, t):
	(a, b) = map(int, input().split())
	g = math.gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


from fractions import gcd
T = int(input())
for _ in range(T):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(a, b) = LI()
		rr.append(IF(math.gcd(a, b) == 1, 'Finite', 'Infinite'))
	return JA(rr, '\n')
print(main())


def gcd(b, s):
	while True:
		tmp = b % s
		if tmp == 0:
			return s
		b = s
		s = tmp
n = int(input())
for _ in range(n):
	(a, b) = [j for j in map(int, input().split(' '))]
	if a >= b:
		g = gcd(a, b)
	else:
		g = gcd(b, a)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


import math
t = int(input())
while t:
	t -= 1
	(x, y) = input().split()
	if math.gcd(int(x), int(y)) == 1:
		print('Finite')
	else:
		print('Infinite')


inputqueue = []

def input_word():
	global inputqueue
	if not inputqueue:
		inputstr = input()
		inputqueue = inputstr.split()
	result = inputqueue[0]
	del inputqueue[0]
	return result
querycount = int(input_word())

def gcd(a, b):
	t = 0
	while b != 0:
		t = a
		a = b
		b = t % b
	return a
for i in range(querycount):
	a = int(input_word())
	b = int(input_word())
	if a == 1 or b == 1 or gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys
FINITE = 'Finite'
INFINITE = 'Infinite'

def main():
	T = read_int()
	for _ in range(T):
		(A, B) = read_ints()
		print(solve(A, B))

def solve(A, B):
	if math.gcd(A, B) == 1:
		return FINITE
	return INFINITE
DEBUG = 'DEBUG' in os.environ

def inp():
	return sys.stdin.readline().rstrip()

def read_int():
	return int(inp())

def read_ints():
	return [int(e) for e in inp().split()]

def dprint(*value, sep=' ', end='\n'):
	if DEBUG:
		print(*value, sep=sep, end=end)
main()


def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('Finite' if gcd(a, b) == 1 else 'Infinite')


from sys import stdin
from math import gcd

def solve(a, b):
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')
t = int(stdin.readline())
for _ in range(t):
	(a, b) = list(map(int, stdin.readline().rstrip().split()))
	solve(a, b)


from fractions import gcd
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	if gcd(n, m) == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
while t:
	(a, b) = map(int, input().split())
	n = 0
	for i in range(2, min(a, b) + 1):
		if a % i == b % i == 0:
			n += 1
			print('Infinite')
			break
	if n == 0:
		print('Finite')
	t -= 1


def gcd(x, y):
	if x % y == 0:
		return y
	if y % x == 0:
		return x
	elif x > y:
		return gcd(y, x % y)
	elif y > x:
		return gcd(x, y % x)
t = int(input())
for i in range(t):
	inp = list(map(int, input().split()))
	a = inp[0]
	b = inp[1]
	c = gcd(a, b)
	if c == 1:
		print('Finite')
	else:
		print('Infinite')


import math
for _ in range(int(input())):
	print('Finite' if math.gcd(*list(map(int, input().split()))) == 1 else 'Infinite')


import fractions
import sys
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(a, b) = [int(item) for item in input().split()]
	gcd = fractions.gcd(a, b)
	if gcd == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
for _ in range(get_int()):
	(a, b) = get_int_list()
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(n, m):
	while m:
		(n, m) = (m, n % m)
	return n
tcs = int(input())
ans = []
for tc in range(tcs):
	(a, b) = map(int, input().split())
	d = gcd(a, b)
	if d == 1:
		ans.append('Finite')
	else:
		ans.append('Infinite')
for a in ans:
	print(a)


def gcd(p, q):
	while q != 0:
		(p, q) = (q, p % q)
	return p

def is_coprime(x, y):
	return gcd(x, y) == 1
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if is_coprime(a, b):
		print('FINITE')
	else:
		print('INFINITE')


from math import gcd
q = int(input())
for queries in range(q):
	(a, b) = map(int, input().split())
	if gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


t = int(input())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
for i in range(t):
	line = input().split()
	a = int(line[0])
	b = int(line[1])
	if gcd(a, b) != 1:
		print('Infinite\n')
	else:
		print('Finite\n')


from math import gcd
for TT in range(1, int(input()) + 1):
	(a, b) = map(int, input().split())
	print(['Infinite', 'Finite'][gcd(a, b) == 1])


t = int(input())
for ttt in range(t):
	(a, b) = list(map(int, input().split()))
	st = False
	for i in range(2, min(a, b) + 1):
		if a % i == 0 and b % i == 0:
			st = True
			break
	if a == 1 or b == 1:
		print('Finite')
	elif st:
		print('Infinite')
	else:
		print('Finite')


n = int(input())
for k in range(n):
	(a, b) = map(int, input().split())
	t = 2
	if a == 1 or b == 1:
		print('Finite')
	else:
		while t <= a and (a % t != 0 or b % t != 0):
			t += 1
		if t > a:
			print('Finite')
		else:
			print('Infinite')


for i in range(int(input())):
	(q, w) = [int(x) for x in input().split()]

	def gcd(a, b):
		if a == 0:
			return b
		return gcd(b % a, a)
	if gcd(q, w) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(m, n):
	if n == 0:
		return m
	return gcd(n, m % n)
for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	print(('Infinite', 'Finite')[gcd(a, b) == 1])


import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

def gcd(a, b):
	if a < b:
		(a, b) = (b, a)
	while b:
		(a, b) = (b, a % b)
	return a
N = int(input())
for _ in range(N):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('FINITE')
	else:
		print('INFINITE')


import math
n = int(input())
for i in range(0, n):
	line = input()
	if len(line.split(' ')) < 2:
		continue
	else:
		()
	a = int(line.split(' ')[0])
	b = int(line.split(' ')[1])
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def hcf(a, b):
	(a, b) = (max(a, b), min(a, b))
	while b:
		(a, b) = (b, a % b)
	return a
for ti in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if hcf(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math

def main():
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().split())
		g = math.gcd(max(a, b), min(a, b))
		if g == 1:
			print('Finite')
		else:
			print('Infinite')
main()


import math
t = int(input())
for k in range(t):
	(a, b) = map(int, input().rstrip().split())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
for _ in range(int(input())):
	print('finite' if gcd(*map(int, input().split())) == 1 else 'infinite')


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
for i in range(t):
	ab = input()
	(a, b) = ab.split()
	a = int(a)
	b = int(b)
	mini = min(a, b)
	maxi = max(a, b)
	if mini == 1:
		print('Finite')
	elif gcd(maxi, mini) != 1:
		print('Infinite')
	else:
		print('Finite')


def factors(n):
	i = 1
	while i <= n:
		k = 0
		if n % i == 0:
			j = 1
			while j <= i:
				if i % j == 0:
					k = k + 1
				j = j + 1
			if k == 2:
				yield i
		i = i + 1

def is_finite(a, b):
	if any(((b - a) % x == 0 for x in factors(b))):
		return False
	return True
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	if is_finite(a, b):
		print('Finite')
	else:
		print('Infinite')


def gcd(x, y):
	if y:
		return gcd(y, x % y)
	return x
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print('infinite' if gcd(a, b) > 1 else 'finite')


t = int(input())
for _ in range(t):
	num = list(map(int, input().split()))
	a = max(num)
	b = min(num)
	if b == 1:
		print('Finite')
	elif a == b:
		print('Infinite')
	else:
		for i in range(2, b + 1):
			if a % i == 0 and b % i == 0:
				print('Infinite')
				break
			elif i == b:
				print('Finite')


import math

def ab():
	(a, b) = list(map(int, input().split()))
	r = int(math.gcd(a, b))
	if r == 1:
		print('Finite')
	else:
		print('Infinite')
k = input()
for i in range(0, int(k)):
	ab()


import math
n = int(input())
for i in range(0, n):
	(a, b) = map(int, input().split(' '))
	if math.gcd(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')


def f(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
x = eval(input())
for i in range(x):
	y = input().split(' ')
	if f(int(y[0]), int(y[1])) == 1:
		print('finite')
	else:
		print('infinite')


def gcd(a, b):
	while b > 0:
		(a, b) = (b, a % b)
	return a
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('FINITE')
	else:
		print('INFINITE')


import sys
import operator
input = sys.stdin.buffer.readline

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
q = int(input())
for _ in range(q):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys, os, io
from math import gcd
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


import math
t = int(input())
for iter in range(t):
	(a, b) = [int(e) for e in input().split()]
	if math.gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


from math import *
from collections import *

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
for y in range(t):
	(a, b) = list(map(int, input().split()))
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys
import math
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))

def solve():
	(a, b) = getList()
	yaku = []
	for i in range(2, a + 1):
		if a % i == 0:
			yaku.append(i)
	for y in yaku:
		if b % y == 0:
			print('Infinite')
			return
	print('Finite')
	return

def main():
	q = getN()
	for _ in range(q):
		solve()
main()


from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
import sys, bisect, math, itertools, string, queue
sys.setrecursionlimit(10 ** 8)
mod = 10 ** 9 + 7

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_str():
	return list(sys.stdin.readline().split())

def inpln(n):
	return list((int(sys.stdin.readline()) for i in range(n)))
n = inp()
ab = [0] * n
for i in range(n):
	ab[i] = inpl()
for i in range(n):
	(a, b) = (ab[i][0], ab[i][1])
	(a, b) = (max(a, b), min(a, b))
	if math.gcd(a, b) != 1 and b != 1:
		print('inFinite')
	else:
		print('finite')


from sys import stdin
from math import gcd
input = stdin.buffer.readline
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	k = math.gcd(a, b)
	if k != 1:
		print('Infinite')
	elif (a + b) % a == 0 and (a + b) % b == 0 and (a != 1) and (b != 1):
		print('Infinite')
	else:
		print('Finite')


def gcd(c, d):
	if d:
		return gcd(d, c % d)
	else:
		return c
t = int(input())
for case in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7

def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
test = int_input()
for _ in range(test):
	(a, b) = multi_int_input()
	gcd = hcfnaive(a, b)
	if a == 1 or b == 1 or gcd == 1:
		print('Finite')
	else:
		print('Infinite')


from math import *
t = int(input())
for i in range(t):
	inp = input()
	inp_arr = inp.split(' ')
	inp_arr = [int(j) for j in inp_arr]
	if gcd(inp_arr[0], inp_arr[1]) == 1:
		print('Finite')
	else:
		print('Infinite')


from sys import stdin
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	(a, b) = mi()
	print('Infinite' if gcd(a, b) != 1 else 'Finite')


import sys
input = sys.stdin.readline
from collections import *
sys.setrecursionlimit(2 * 10 ** 5)
from math import *
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	if gcd(n, m) == 1:
		print('Finite')
	else:
		print('Infinite')


def rcnpm(x):
	a = 2
	d = []
	X = x
	while a ** 2 <= X:
		if x % a == 0:
			d.append(a)
			x //= a
			a -= 1
		a += 1
	if x != 1:
		d.append(x)
	return d

def nod(a, b):
	d1 = rcnpm(a)
	d2 = rcnpm(b)
	L = len(d1)
	d0 = []
	n = 1
	for el in d1:
		el = int(el)
		if el not in d0:
			d0.append(el)
			k1 = d1.count(el)
			k2 = d2.count(el)
			if k2 != 0:
				n *= min(k1, k2) * el
	return n
h = int(input())
for i in range(h):
	(a, b) = [int(i) for i in input().split()]
	nd = nod(a, b)
	if nd > 1:
		print('Infinite')
	else:
		print('Finite')


import math
for _ in [0] * int(input()):
	(a, b) = map(int, input().split())
	print('In' * (math.gcd(a, b) > 1) + 'finite')


t = int(input())
while t:
	t -= 1
	(x, y) = map(int, input().split())
	while y:
		(x, y) = (y, x % y)
	if x == 1:
		print('Finite')
	else:
		print('Infinite')


n = int(input())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)
for i in range(n):
	s = input().split(' ')
	a = int(s[0])
	b = int(s[1])
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('infinite')


import math
numero = int(input())
while numero > 0:
	(x, y) = map(int, input().split())
	if math.gcd(x, y) == 1:
		print('Finite')
	else:
		print('Infinite')
	numero -= 1


t = int(input())
for i in range(t):
	flag = 0
	(a, b) = map(int, input().split())
	if a == b and a > 1 and (b > 1):
		print('Infinite')
	else:
		for j in range(2, min(a, b) + 1):
			if a % j == b % j == 0:
				flag = 1
				break
		if flag == 1:
			print('Infinite')
		else:
			print('Finite')


def nod(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
from sys import stdin
input = stdin.readline
R = lambda : list(map(int, input().split()))
(q,) = R()
for i in range(q):
	(a, b) = R()
	if nod(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math
a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	d = math.gcd(b, c)
	if b == 1 or c == 1:
		print('finite')
	elif (b != 1 or c != 0) and d == 1:
		print('finite')
	else:
		print('infinite')


import math
q = int(input())
for s in range(q):
	inf = 0
	(a, b) = map(int, input().split(' '))
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
for i in range(iread()):
	(a, b) = viread()
	print(f"{('' if math.gcd(a, b) == 1 else 'in')}finite")


from math import gcd
for i in range(int(input())):
	(N, M) = map(int, input().split())
	if gcd(N, M) == 1:
		print('Finite')
	else:
		print('Infinite')


def f(l):
	(a, b) = l
	if a > b:
		(a, b) = (b, a)
	bl = [False] + [True] * (a - 1)
	for i in range(1, a + 1):
		bl[i * b % a] = False
	return sum(bl) > 0
t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	print('Infinite' if f(l) else 'Finite')


for i in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	(a, b) = (max(a, b), min(a, b))

	def hcf(x, y):
		if x > y:
			smaller = y
		else:
			smaller = x
		for i in range(1, smaller + 1):
			if x % i == 0 and y % i == 0:
				hcf = i
		return hcf
	c = hcf(a, b)
	if a % b == 0 and b > 1:
		y = 1
	elif b == 1:
		y = 0
	elif c > 1:
		y = 1
	else:
		y = 0
	if y == 1:
		print('Infinite')
	else:
		print('Finite')


import os
import sys
from collections import deque, defaultdict
import math

class Pair:

	def __init__(self, x, y):
		self.x = x
		self.y = y
t = int(input())
for i in range(t):
	arr = list(map(int, input().split()))
	if math.gcd(arr[0], arr[1]) == 1:
		print('FINITE')
	else:
		print('INFINITE')


t = int(input())
while t:
	t -= 1
	(a, b) = map(int, input().split())
	l1 = []
	l2 = []
	i = 2
	t1 = 0
	t2 = -1
	c = 0
	while i <= a or i <= b:
		if i <= a:
			if a % i == 0:
				l1.append(i)
				t1 = i
		if i <= b:
			if b % i == 0:
				l2.append(i)
				t2 = i
		i += 1
		if t1 == t2:
			print('Infinite')
			c = 1
			break
	if c == 0:
		print('Finite')


import sys
if sys.version_info.minor >= 5:
	from math import gcd
else:
	from fractions import gcd

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	(a, b) = MAP()
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
answer = []

def gcd(a, b):
	if a == 0:
		return b
	elif a == 1:
		return 1
	else:
		return gcd(b % a, a)
for i in range(t):
	(a, b) = list(map(int, input().split()))
	if gcd(a, b) > 1:
		answer.append('Infinite')
	else:
		answer.append('Finite')
for i in range(t):
	print(answer[i])


n = int(input())
for j in range(n):
	(a, b) = map(int, input().split(' '))
	if (a or b) == 1:
		print('Finite')
	elif a == b:
		print('Infinite')
	else:
		for i in range(a * b):
			if a >= b:
				a = a - b
			else:
				b = b - a
			if a == 1 or b == 1:
				print('Finite')
				break
			elif a - b == 0:
				print('infinite')
				break


import math

def solve():
	(a, b) = map(int, input().split())
	if math.gcd(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')
t = int(input())
for _ in range(t):
	solve()


import math
n = int(input().strip())
res = []
for _ in range(n):
	(a, b) = [int(x) for x in input().strip().split()]
	res.append('Finite' if math.gcd(a, b) == 1 else 'Infinite')
for e in res:
	print(e)


import math, string, itertools, fractions, heapq, collections, re, array, bisect
INF = 'Infinite'
FIN = 'Finite'
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print(FIN)
	else:
		print(INF)


from math import gcd
import sys
Input = sys.stdin.readline
n = int(Input())
for i in range(n):
	(a, b) = list(map(int, Input().split()))
	print('Finite' if gcd(a, b) == 1 else 'Infinite')


from sys import stdout, stdin, exit
for i in stdin:
	t = int(i)
	break
while t:
	for i in stdin:
		(a, b) = list(map(int, i.strip().split()))
		break
	if a == 1 or b == 1:
		stdout.write('Finite\n')
	else:

		def GCD(a, b):
			if a == 0:
				return b
			else:
				return GCD(b % a, a)
		if GCD(a, b) == 1:
			stdout.write('Finite\n')
		else:
			stdout.write('Infinite\n')
	t -= 1


t = int(input())
s = []
for kngg in range(0, t):
	x = input()
	xx = x.split()
	xx[0] = int(xx[0])
	xx[1] = int(xx[1])
	xx.sort()
	a = xx[0]
	b = xx[1]
	while a != 0:
		b -= a
		if a > b:
			c = b
			b = a
			a = c
	if b == 1:
		s.append('finite')
	else:
		s.append('infinite')
for i in s:
	print(i)


tests = int(input())
for _ in range(tests):
	(n, k) = map(int, input().split())
	(n, k) = (max(n, k), min(n, k))
	while n % k != 0:
		n %= k
		(n, k) = (k, n)
	if k == 1:
		print('Finite')
	else:
		print('Infinite')


a = int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
for i in range(a):
	(a, b) = map(int, input().split())
	g = find_gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def dfs(u, graph, grp, c):
	if grp[u] != -1:
		return
	grp[u] = c
	for kid in graph[u]:
		dfs(kid, graph, grp, int(not c))

def main():
	(a, b) = M()
	if mt.gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')
tc = 1
tc = I()
for _ in range(tc):
	main()


t = int(input())

def GCD(a, b):
	if b == 0:
		return a
	return GCD(b, a % b)
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	gcd_ = GCD(a, b)
	if gcd_ == 1:
		print('Finite')
	else:
		print('Infinite')


arr = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	if a + b == 1:
		arr.append('finite')
	else:
		arr.append('infinite')
for i in arr:
	print(i)


def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
t = int(input())
while t:
	t -= 1
	(a, b) = tuple(map(int, input().split()))
	GCD = gcd(a, b)
	if GCD == 1:
		print('Finite')
	else:
		print('Infinite')


import math
from collections import deque

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	(a, b) = mi()
	x = math.gcd(a, b)
	if x > 1:
		print('Infinite')
	else:
		print('Finite')


def gcd(a, b):
	while b != 0:
		a = a % b
		r = a
		a = b
		b = r
	return a
from sys import stdin, stdout
a = int(stdin.readline())
for i in range(a):
	(b, c) = map(int, stdin.readline().split())
	if gcd(b, c) != 1:
		stdout.write('Infinite\n')
	else:
		stdout.write('Finite\n')


from math import gcd as g
t = int(input())
while t:
	t += -1
	(a, b) = [int(x) for x in input().split()]
	if g(a, b) == 1:
		print('fiNItE')
	else:
		print('infinite')


from collections import defaultdict as dc
import sys
input = sys.stdin.readline
import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import *
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x = gcd(a, b)
	if x != 1 and a % x == 0 and (b % x == 0):
		print('Infinite')
	else:
		print('Finite')


def isFinite(a, b):
	if gcd(a, b) > 1 and min(a, b) > 1:
		return 'Infinite'
	else:
		return 'Finite'

def gcd(a, b):
	if a == 0:
		return b
	if b == 0:
		return a
	if a >= b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	print(isFinite(a, b))


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : list(map(int, input().split()))
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from math import gcd
for _ in range(ii()):
	(a, b) = f()
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


for _ in range(int(input())):
	(a, b) = [int(i) for i in input().split()]
	if a == 0 or b == 0:
		print('Finite')
	else:
		Flag = False
		for i in range(2, min(a, b) + 1):
			if a % i == 0 and b % i == 0:
				print('Infinite')
				Flag = True
				break
		if not Flag:
			print('Finite')


def lcm(a, b):
	m = a * b
	while a != 0 and b != 0:
		if a > b:
			a %= b
		else:
			b %= a
	return m // (a + b)
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	q = lcm(a, b)
	if q == a * b:
		print('Finite')
	else:
		print('Infinite')


t = int(input())
import math
for i in range(t):
	(a, b) = map(int, input().split())
	x = math.gcd(a, b)
	if x == 1:
		print('FINITE')
	else:
		print('INFINITE')


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a
t = int(input())
ans_arr = []
for i in range(t):
	[a, b] = [int(i) for i in input().split()]
	if gcd(a, b) == 1:
		ans_arr.append('Finite')
	else:
		ans_arr.append('Infinite')
print('\n'.join(ans_arr))


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
for _ in range(inn()):
	(a, b) = value()
	ans = 'Finite'
	if gcd(a, b) > 1:
		ans = 'Infinite'
	print(ans)


n = int(input())

def gcd(a, b):
	if a > b:
		oa = a
		a = b
		b = oa
	if a == 0:
		return b
	return gcd(a, b % a)
for i in range(0, n):
	ln = [int(j) for j in input().split(' ')]
	a = ln[0]
	b = ln[1]
	g = gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(l, n):
	if l > n:
		(n, l) = (l, n)
	while l != 0:
		temp = l
		l = n % l
		n = temp
	return n
t = int(input())
for _ in range(t):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	if gcd(a, b) == 1:
		print('finite')
	else:
		print('infinite')


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for i in range(ii()):
	(a, b) = mi()
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import sys

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)
n = int(sys.stdin.readline())
for i in range(n):
	(a, b) = map(int, sys.stdin.readline().strip().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import ceil

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_product(n, m, arr):
	product = 1
	if n <= m:
		for i in range(n):
			for j in range(i + 1, n):
				product = product * abs(arr[i] - arr[j]) % m
		return product
	return 0

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)
t = 1
t = int(input())
while t:
	t = t - 1
	(a, b) = map(int, input().split())
	if gcd(a, b) > 1:
		print('Infinite')
	else:
		print('Finite')


import sys
import math
import itertools
import collections

def getdict(n):
	d = {}
	if type(n) is list or type(n) is str:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ' '.join(map(str, arr))

def revn(n):
	return int(str(n)[::-1])

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
t = ii()
for _ in range(t):
	(a, b) = mi()
	if math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


import math as m
T = int(input())
while T != 0:
	T = T - 1
	(a, b) = (int(x) for x in input().split())
	g = m.gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def main():
	import sys
	input = sys.stdin.readline
	q = int(input())
	for __ in [0] * q:
		(a, b) = map(int, input().split())
		if gcd(a, b) == 1:
			print('Finite')
		else:
			print('Infinite')
main()
3


import math
for _ in [0] * int(input()):
	print('IFnifniintiet e'[math.gcd(*map(int, input().split())) < 2::2])


import sys

def division(a, b):
	for i in range(2, min(a, b) + 1):
		if a % i == 0 and b % i == 0:
			return False
	return True
try:
	while True:
		line = input()
		inter = int(line)
		for i in range(inter):
			line = input()
			x = line.split()
			y = division(int(x[0]), int(x[1]))
			if y == True:
				print('finite')
			else:
				print('Infinite')
except:
	pass


from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)

def inp():
	return int(sys.stdin.readline())

def inpl():
	return list(map(int, sys.stdin.readline().split()))

def inpl_str():
	return list(sys.stdin.readline().split())
t = inp()

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a
for _ in range(t):
	(a, b) = inpl()
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def gcd(a, b):
	if a % b == 0:
		return b
	return gcd(b, a % b)
t = int(input())
for you in range(t):
	l = input().split()
	a = int(l[0])
	b = int(l[1])
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from sys import stdin
from math import gcd
t = int(stdin.readline().strip())
for i in range(t):
	(a, b) = map(int, stdin.readline().strip().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
t = int(input())
for tt in range(0, t):
	(a, b) = [int(x) for x in input().split()]
	if a == 1 or b == 1:
		print('Finite')
	elif abs(a - b) == 0:
		print('Infinite')
	elif gcd(a, b) != 1:
		print('Infinite')
	else:
		print('Finite')


import math
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	res = str('FINITE') if math.gcd(a, b) == 1 else str('INFINITE')
	print(res)


from sys import stdin
import math
A = int(stdin.readline())
for t in range(0, A):
	B = list(map(int, stdin.readline().split()))
	C = math.gcd(B[0], B[1])
	if C == 1:
		print('Finite')
	else:
		print('Infinite')


import sys, math, queue, collections
MOD = 10 ** 9 + 7
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	g = math.gcd(a, b)
	if g == 1:
		print('Finite')
	else:
		print('Infinite')


def nod(a, b):
	if b == 0:
		return a
	else:
		return nod(b, a % b)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().split())
	k = nod(a, b)
	if k == 1:
		print('Finite')
	else:
		print('Infinite')


n = int(input())

def gcd(x, y):
	while x != 0 and y != 0:
		(x, y) = (max(x, y), min(x, y))
		x %= y
	return y
for i in range(n):
	(a, b) = map(int, input().split())
	if gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


t = int(input())

def ebob(a, b):
	(c, d) = ([], [])
	for i in range(1, a + 1):
		if a % i == 0:
			c.append(i)
			for k in c:
				if b % k == 0:
					d.append(k)
	return d[-1]
for _ in range(t):
	(a, b) = map(int, input().split())
	if ebob(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


def hcfnaive(a, b):
	if b == 0:
		return a
	else:
		return hcfnaive(b, a % b)
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if hcfnaive(a, b) == 1:
		print('finiTE')
	else:
		print('inFiNite')


import sys

def readline():
	return input()

def computeGCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def fun(a, b):
	if computeGCD(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')
q = int(readline())
for i in range(q):
	v = list(map(int, readline().split(' ')))
	ans = fun(v[0], v[1])


def hcf(a, b):
	if a % b == 0:
		return b
	else:
		return hcf(b, a % b)
t = int(input())
for i in range(t):
	(a, b) = list(map(int, input().strip().split()))
	if hcf(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from math import gcd
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	print(('IN', '')[gcd(a, b) == 1] + 'FINITE')


import math
T = int(input())
for i in range(T):
	(a, b) = map(int, input().strip().split())
	x = math.gcd(a, b)
	if x == 1:
		print('Finite')
	else:
		print('Infinite')


import math
t = int(input())
for _ in range(t):
	(a, b) = list(map(int, input().split()))
	if a == 1 or b == 1:
		print('Finite')
	elif math.gcd(a, b) == 1:
		print('Finite')
	else:
		print('Infinite')


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping
from itertools import groupby as gb

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
while n:
	n -= 1
	(a, b) = map(int, input().split())
	if min(a, b) == 1:
		print('finite')
	elif a == b:
		print('infinite')
	elif math.gcd(a, b) != 1:
		print('infinite')
	else:
		print('finite')


import math
for tc in [0] * int(input()):
	(a, b) = map(int, input().split())
	if math.gcd(a, b) == 1:
		print('FINITE')
	else:
		print('INFINITE')