Good ol' Numbers Coloring
Contest: Codeforces Round 597 (Div. 2)
Difficulty rating: 1000
Tags: math, number theory

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 format:
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 format:
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).

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Example input:
4
10 10
1 10
6 9
7 3

Example output:
Infinite
Finite
Infinite
Finite

Editorial:
If $$$\gcd(a, b) \neq 1$$$, print "Infinite". This is correct because any integer that isn't divisible by $$$\gcd(a, b)$$$ will not be expressible in the form $$$ax + by$$$ since $$$ax + by$$$ is always divisible by $$$\gcd(a, b)$$$.
Otherwise, print "Finite". To show that this is correct, we will prove that any integer greater than $$$ab$$$ is colored white. Let $$$x$$$ be an integer greater than $$$ab$$$. Consider the set $$$S = \{x, x - a, x - 2a, \ldots, x - (b - 1) a\}$$$. If, for any $$$y \in S$$$, $$$y$$$ is divisible by $$$b$$$, we are done. Otherwise, by the pigeonhole principle, there exists distinct $$$x - sa, x - ta \in S$$$ such that they have the same remainder when divided by $$$b$$$, thus $$$b$$$ divides $$$(x - sa) - (x - ta) = a (t - s)$$$. WLOG, let $$$s < t$$$. Thus, $$$0 < t - s$$$ and $$$b$$$ divides $$$t - s$$$, since $$$\gcd(a, b) = 1$$$. But $$$t - s \leq t < b$$$. However, it is not possible for $$$b$$$ to divide any integer $$$x$$$ such that $$$0 < x < b$$$, thus we arrive at a contradiction.