Chef has recently learned about number bases and is becoming fascinated.
Chef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For example, in base 16, the digits are 0123456789ABCDEF. Chef thought that this is unsustainable; the English alphabet only has 26 letters, so this scheme can only work up to base 36. But this is no problem for Chef, because Chef is very creative and can just invent new digit symbols when she needs them. (Chef is very creative.)
Chef also noticed that in base two, all positive integers start with the digit 1! However, this is the only base where this is true. So naturally, Chef wonders: Given some integer N, how many bases b are there such that the base-b representation of N starts with a 1?

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
Each test case consists of one line containing a single integer N (in base ten).

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

-----Constraints-----

-----Subtasks-----Subtask #1 (16 points):
- 1 ≤ T ≤ 103
- 0 ≤ N < 103
Subtask #2 (24 points):
- 1 ≤ T ≤ 103
- 0 ≤ N < 106
Subtask #3 (28 points):
- 1 ≤ T ≤ 103
- 0 ≤ N < 1012
Subtask #4 (32 points):
- 1 ≤ T ≤ 105
- 0 ≤ N < 1012

-----Example-----
Input:4
6
9
11
24

Output:4
7
8
14

-----Explanation-----
In the first test case, 6 has a leading digit 1 in bases 2, 4, 5 and 6: 610 = 1102 = 124 = 115 = 106.

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
def finder(n):
    cnt=0
    for i in range(2,n+1):
        a=n
        while a!=0:
            r=a%i
            a=a//i
        if r==1:
            cnt+=1
    return cnt

t=int(input())
for _ in range(t):
    n=int(input())
    if n==0:
        print(0)
    elif n==1:
        print('INFINITY')
    else:
        print(finder(n))
    

import math


def bases(n):
    n = int(n)
    if n == 0:
        return('0')
    elif n == 1:
        return('INFINITY')
    else:
        sumas = 1
        i = 2
        while i < n:
            arreglo = primer_digito(n, i)
            potencia = arreglo[1]
            primer = arreglo[0]
            resto = n - (i ** potencia)
            if primer == 1 and potencia == 1:
                sumas += resto
                i += resto
            elif primer == 1:
                sumas += 1
                i += 1
            else:
                i += 1
        return sumas


def primer_digito(numero, base):
    potencia = int(math.log(numero, base))
    primer = numero // (base ** potencia)
    if primer >= base:
        primer = primer / base
        potencia += 1
    arreglo = [primer, potencia]
    return arreglo


casos = input()
for i in range(int(casos)):
    numero = input()
    print(bases(numero))


#sabemos que no existe una base B>N donde el número empieze con 1 analizamos los casos 0,1 y los demás enteros
T=input() #casos a analizar
T=int(T)
for a in range(0,T):
    N=input() #número de base
    N=int(N)
    unos = 1
    if N==1:
        print('INFINITY')
    elif N==0:
        print(0)
    else:
        for b in range(3,N+1):
            a=N
            while a>=b:
                a = int(a/b)
                if a==1:
                    unos+=1
        print(unos)

# cook your dish here
n=int(input())
def dig(num,b):
    c=0
    mul=b
    while(True):
        if(num//mul!=0):
            mul=mul*b
            c+=1 
        else:
            break
    return c 
for q in range(n):
    num=int(input())
    res=0
    for i in range(3,num):
        po=dig(num,i)
        if((2*(i**po)-1)>=num):
            res+=1 
    if(num==2):
        res=res+1 
    if(num>2):
        res=res+2
    if(num==1):
        print("INFINITY")
    else:
        print(res)
    

t = int(input())
for i in range(0, t):
    n = int(input())
    c = 1
    if n == 0:
        print(0)
    elif n == 1:
        print("INFINITY")
    else:
        for j in range(3, n+1):
            a = n
            while a >= j:
                a = int(a/j)
            if a == 1:
                c = c+1
        print(c)
        

t=eval(input())
for g in range(t):
    n=int(input())
    if n==0:
        print(0)
    elif n==1:
        print('INFINITY')
    else:
        a=0
        for x in range(2,n):
            k=1
            while n>=x**k:
                k+=1
            k-=1
            if 2*(x**k)>n:
                a+=1



        print(a+1)


from math import sqrt as S 
for _ in range(int(input())):
    n=int(input())
    if n==1:
        print('INFINITY')
        continue 
    else:
        ans=0 
        z=int(S(n))
        for i in range(2,z+1):
            temp=n 
            while temp:
                r=temp%i 
                temp=temp//i 
            if r==1: ans+=1
        k=n//2 
        if n>k:
            ans+=n-k 
        print(ans)

for _ in range(int(input())):
    n=int(input())
    cnt=0
    for i in range(2,n+1):
        temp=n 
        while temp:
            r=temp%i 
            temp=temp//i 
        if r==1:
            cnt+=1
    if n==1:
        print('INFINITY')
    else:
        print(cnt)