Last Updated: 14 Oct, 2025

First Digit One

Moderate

Problem statement

Ninja is exploring number base representations. He knows that for any integer N, its representation in base b is a sequence of digits dk d{k-1} ... d0 such that N = dk * b^k + ... + d0, where 0 <= di < b.


He wonders: for a given integer N, how many integer bases b (where b >= 2) exist such that the base-b representation of N starts with the digit 1?


For example, consider N = 6:

  In base 2: 6 = (110)_2. Starts with 1.
  In base 3: 6 = (20)_3. Does not start with 1.
  In base 4: 6 = (12)_4. Starts with 1.
  In base 5: 6 = (11)_5. Starts with 1.
  In base 6: 6 = (10)_6. Starts with 1.
For N=6, there are 4 such bases: 2, 4, 5, 6.


Your task is to find this count for any given N. If the number of such bases is infinite, you should report it.


Input Format:
The first line contains an integer T, the number of test cases.

Each of the next T lines contains a single integer N.


Output Format:
For each test case, print a single line containing the number of bases b, or INFINITY if there are an infinite number of them.


Note:
An element from array 'a' and an element from array 'b' can be part of only one pair. Once used, they cannot be used again to form another pair.