This page is still under construction.

Parts of this page are still being built. What you see may change.

Homework

Time limit2sMemory limit256 MB

Summary
For each triple of decimal strings x, y, z, decide whether infinitely many bases k make x times y equal z when read in base k.
Level

Hard8 of 10

Topics
Math, Number theory, Implementation, Brute force
Solved
No attempts yet

Problem

In informatics class today, Petya learned about numeral systems with different bases. A base-kk numeral system uses digits with weights from 0 to k−1k-1; the first 10 digits are written with ordinary digits, and beyond that Latin letters and other symbols are also used.

Now Petya is trying to solve the following homework. Numbers xx, yy, and zz written with decimal digits are given. Find every base kk such that all digits used in the numbers exist in this numeral system and, when xx, yy, and zz are treated as numbers written in base kk, the product of xx and yy equals zz.

Petya started solving this problem and discovered that under some conditions infinitely many different values of kk work. He decided to first determine whether this case occurs. Help him find out.

Input

The first line contains the number tt, the number of tests in the input (1≤t≤10001 \le t \le 1000).

Then follow tt test descriptions. Each test is described by three lines containing the numbers xx, yy, and zz, respectively. Each of these numbers is positive, consists only of decimal digits, and has no leading zeros. The length of each of xx and yy does not exceed 100, and the length of zz does not exceed 200.

Output

For each test, output its answer on a separate line: Infinity if there are infinitely many values of kk such that treating the input numbers as written in base kk makes the product of xx and yy equal zz, or Finite if there are finitely many such kk.

Examples1

  1. Example 1

    Input
    4
    1
    1
    1
    2
    2
    10
    11
    11
    121
    1
    1
    10
    
    Expected output
    Infinity
    Finite
    Infinity
    Finite