import math

def primeFactors(n):
    d = {}

    while n % 2 == 0:
        try:
            d[2]+=1
        except:
            d[2]=1

        n = n // 2

    for i in range(3, int(math.sqrt(n))+1, 2):

        while n % i == 0:
            try:
                d[i]+=1
            except:
                d[i]=1
            n = n // i

    if n > 2:
        try:
            d[n]+=1
        except:
            d[n]=1

    return d

t=int(input())
while t:
    t-=1
    n=int(input())

    d=primeFactors(n)
    # print(d)
    flag=0
    s=0
    toprint=[]

    if len(d)==1:
        for i in d:
            if d[i]>=6:
                flag=1
                toprint=[i,i**2,i**(d[i]-3)]

    elif len(d)>=3:
        flag=1
        cnt=0
        mul=1
        for i in d:
            if cnt==0:
                toprint.append(i)
            elif cnt==1:
                toprint.append(i)
            else:
                mul*=i
            cnt+=1
        toprint.append(mul)

    elif len(d)==2:
        keys=list(d.keys())
        if d[keys[0]]+d[keys[1]]>3:
            flag=1
            toprint=[keys[0],keys[1],(keys[0]**(d[keys[0]]-1))*(keys[1]**(d[keys[1]]-1))]

    if len(set(toprint))<3:
        flag=0
    if flag:
        print('YES')
        for i in toprint:
            print(i,end=' ')
        print()
    else:
        print('NO')


from math import *

for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []
    sq = int(sqrt(n))

    while n > 1:
        if n % now == 0:
            while n % now == 0:
                l.append(now)
                n //= now
        else:
            now += 1

        if now > sq:
            break

    if len(l) < 2:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])
    elif len(l) == 2:
        print("NO")
        continue
    else:
        m.append(l[1] * l[2])

    t = nn // (m[0] * m[1])

    if (t == 1) or (t in m):
        print("NO")
        continue
    else:
        print("YES")
        print(m[0], m[1], t)


from math import *

es = []
end = int(sqrt(1000000001))

for x in range(end + 1):
    es.append(x)

es[1] = 0
ee = []

for x in range(2, end + 1):
    for y in range(x + x, end + 1, x):
        es[y] = 0

for x in es:
    if x != 0:
        ee.append(x)

for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []
    ns = int(sqrt(n)) + 1
    i = 0

    while n > 1:
        if now > ns:
            break
        elif now not in es:
            i += 1
            now = ee[i]
        elif n % now == 0:
            l.append(now)
            n //= now
        else:
            i += 1
            now = ee[i]

        if len(l) >= 3:
            break

    if len(l) < 2:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])
    else:
        m.append(l[1] * l[2])

    t = nn // (m[0] * m[1])

    if (t == 1) or (t in m):
        print("NO")
        continue
    else:
        print("YES")
        print(m[0], m[1], t)


from math import *

for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []
    sq = int(sqrt(n))

    while n > 1:
        if n % now == 0:
            while n % now == 0:
                l.append(now)
                n //= now
        else:
            now += 1

        if (len(l) >= 2) or (now > sq):
            break

    if len(l) < 2:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])
    else:
        m.append(l[1] * l[2])

    t = nn // (m[0] * m[1])

    if (t == 1) or (t in m):
        print("NO")
        continue
    else:
        print("YES")
        print(m[0], m[1], t)


for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []

    while n > 1:
        if n % now == 0:
            l.append(now)
            n //= now
        else:
            now += 1

    if len(l) < 3:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])

        t = 1

        for x in l[2:]:
            t *= x

            if t not in m:
                m.append(t)
                break

    else:
        m.append(l[1] * l[2])

        t = 1

        for x in l[3:]:
            t *= x

            if t not in m:
                m.append(t)
                break

    if len(m) < 3:
        print("NO")
    else:
        print("YES")
        print(m[0], m[1], nn // (m[0] * m[1]))


from math import *

es = []
end = int(sqrt(1000001001))

for x in range(end + 1):
    es.append(x)

es[1] = 0
ee = []

for x in range(2, end + 1):
    for y in range(x + x, end + 1, x):
        es[y] = 0

for x in es:
    if x != 0:
        ee.append(x)

lenee = len(ee)

for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []
    ns = int(sqrt(n)) + 1
    i = 0

    while n > 1:
        if (now > ns) or (i + 1 >= lenee):
            break
        elif now not in es:
            i += 1
            now = ee[i]
        elif n % now == 0:
            l.append(now)
            n //= now
        else:
            i += 1
            now = ee[i]

        if len(l) >= 3:
            break

    if len(l) < 2:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])
    elif len(l) == 2:
        print("NO")
        continue
    else:
        m.append(l[1] * l[2])

    t = nn // (m[0] * m[1])

    if (t == 1) or (t in m):
        print("NO")
        continue
    else:
        print("YES")
        print(m[0], m[1], t)


for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []

    while n > 1:
        if n % now == 0:
            l.append(now)
            n //= now
        else:
            now += 1

        if len(l) >= 3:
            break

    if len(l) < 3:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])
    else:
        m.append(l[1] * l[2])

    t = nn // (m[0] * m[1])

    if (t == 1) or (t in m):
        print("NO")
        continue
    else:
        print("YES")
        print(m[0], m[1], t)


from math import *

es = []
end = int(sqrt(1000001001))

for x in range(end + 1):
    es.append(x)

es[1] = 0
ee = []

for x in range(2, end + 1):
    for y in range(x + x, end + 1, x):
        es[y] = 0

for x in es:
    if x != 0:
        ee.append(x)

lenee = len(ee)

for _ in range(int(input())):
    n = int(input())
    nn = n
    l = []
    now = 2
    m = []
    ns = int(sqrt(n)) + 1
    i = 0

    while n > 1:
        if (now > ns) or (i + 1 >= lenee):
            break
        elif now not in es:
            i += 1
            now = ee[i]
        elif n % now == 0:
            l.append(now)
            n //= now
        else:
            i += 1
            now = ee[i]

        if len(l) >= 3:
            break

    if len(l) < 2:
        print("NO")
        continue

    m.append(l[0])

    if l[0] != l[1]:
        m.append(l[1])
    else:
        m.append(l[1] * l[2])

    t = nn // (m[0] * m[1])

    if (t == 1) or (t in m):
        print("NO")
        continue
    else:
        print("YES")
        print(m[0], m[1], t)


def find(n):
  a=0
  b=0
  i=2
  A=[]
  while (i*i)<=n:
    if num%i==0:
      A.append(i)
      n=n//i
    i+=1
  return A
for i in range(int(input())):
    n=int(input())
    A=find(n)
    if len(A)>=2 and n>1:
      print("YES")
      print(A[0],A[1],n)
    else:print("NO")


def find(num):
  a=0
  b=0
  i=2
  while (i*i)<=num:

    if num%i==0:
      if a==0:a=i
      elif b==0:b=i
      num=num//i

    if a>0 and b>0:
      return [a,b]
    i+=1
  return None
for i in range(int(input())):
    #print(i+1,end=" ")

    n=int(input())
    print(n)
    A=find(n)
    if not A or n<=2:print("NO")
    else:
     a=A[0]
     b=A[1]
     c=a*b
     if n%a==0 and n//a!=a and n//a!=b and (a*b*(n//a))==n:
        print("YES")
        print(a,b,n//a)
     if n%b==0 and n//b!=a and n//b!=b and (a*b*(n//b))==n:
       print("YES")
       print(a,b,n//b)
     elif n%c==0 and n//c!=a and n//c!=b and (a*b*(n//c))==n:
       print("YES")
       print(a,b,n//c)
     else:print("NO")


def find(num):
  a=0
  b=0
  i=2
  while (i*i)<=n:
    nn=num//i
    if num%i==0:
      if a==0:a=i
      elif b==0:b=i

    if a>0 and b>0:
      return [a,b]
    i+=1
  return None
for _ in range(int(input())):
    n=int(input())
    A=find(n)
    if not A:
      print("NO")
    else:
     a=A[0]
     b=A[1]
     c=A[0]*A[1]
     if n%c!=0 or n//c==a or n//c==b:print("NO")
     elif n%c==0:
       print("YES")
       print(a,b,n//c)


def find(num):
  a=0
  b=0
  i=2
  while (i*i)<=num:

    if num%i==0:
      if a==0:a=i
      elif b==0:b=i
      num=num//i

    if a>0 and b>0:
      return [a,b]
    i+=1
  return None
for i in range(int(input())):
    n=int(input())
    A=find(n)
    if not A or n<=2:print("NO")
    else:
     a=A[0]
     b=A[1]
     c=a*b
     if n%a==0 and n//a!=a and n//a!=b and (a*b*(n//a))==n:
        print("YES")
        print(a,b,n//a)
     if n%b==0 and n//b!=a and n//b!=b and (a*b*(n//b))==n:
       print("YES")
       print(a,b,n//b)
     elif n%c==0 and n//c!=a and n//c!=b and (a*b*(n//c))==n:
       print("YES")
       print(a,b,n//c)
     else:print("NO")


def find(num):
  a=0
  b=0
  i=2
  while (i*i)<=n:
    nn=num//i
    if num%i==0:
      if a==0:a=i
      elif b==0:b=i

    if a>0 and b>0:
      return [a,b]
    i+=1
  return None
for i in range(int(input())):
    #print(i+1,end=" ")
    n=int(input())
    A=find(n)
    if not A or n<=2:print("NO")
    else:
     a=A[0]
     b=A[1]
     c=A[0]*A[1]
     if n%c!=0 or n//c==a or n//c==b:print("NO")
     elif n%c==0:
       print("YES")
       print(a,b,n//c)


for _ in range(int(input())):
    n = int(input())

    flag = False

    for i in range(2, int(n // 4)):
        if n % i == 0:
            a = i
            n = n / i

            for j in range(a + 1, int(n // 2)):
                if n % j == 0:
                    b = j
                    c = int(n / j)

                    if c != b:
                        print('YES')
                        print(a, b, c)
                        flag = True
                        break
        if flag is True:
            break

    if flag is False:
        print('NO')


for _ in range(int(input())):
    n = int(input())

    flag = False

    for i in range(2, int(n // 4)):
        if n % i == 0:
            a = i
            n = n / i

            for j in range(a + 1, int(n // 2)):
                if n % j == 0:
                    b = j
                    c = int(n / j)

                    if c != b and a != c:
                        print('YES')
                        print(a, b, c)
                        flag = True
                        break
        if flag is True:
            break

    if flag is False:
        print('NO')


import math

for _ in range(int(input())):
    n = int(input())

    flag = False

    if n < 24:
        print('NO')
    elif n == 24:
        print('YES')
        print(2, 3, 4)
    else:

        for i in range(2, int(math.sqrt(n))):
            if n % i == 0:
                a = i
                n = n / i

                for j in range(a + 1, int(math.sqrt(n))):
                    if n % j == 0:
                        b = j
                        c = int(n / j)

                        if c != b and a != c:
                            print('YES')
                            print(a, b, c)
                            flag = True
                            break
            if flag is True:
                break

        if flag is False:
            print('NO')


import math

for _ in range(int(input())):
    n = int(input())

    flag = True
    simple = True

    if n < 24:
        flag = False
    else:
        for i in range(2, int(math.sqrt(n))):
            if n % i == 0:
                simple = False
                break

    if flag is False or simple is True:
        print('NO')
    else:
        for i in range(2, int(n // 4)):
            if n % i == 0:
                a = i
                n = int(n / i)

                for j in range(a + 1, int(n // 2)):
                    if n % j == 0:
                        b = j
                        c = int(n / j)

                        if c != b and a != c:
                            print('YES')
                            print(a, b, c)
                            flag = True
                            break
                        else:
                            flag = False

                    else:
                        flag = False

        if flag is False:
            print('NO')


import math

for _ in range(int(input())):
    n = int(input())

    flag = False

    if n < 24:
        print('NO')
    else:

        for i in range(2, int(math.sqrt(n))):
            if n % i == 0:
                a = i
                n = n / i

                for j in range(a + 1, int(math.sqrt(n))):
                    if n % j == 0:
                        b = j
                        c = int(n / j)

                        if c != b and a != c:
                            print('YES')
                            print(a, b, c)
                            flag = True
                            break
            if flag is True:
                break

        if flag is False:
            print('NO')


import math

for _ in range(int(input())):
    n = int(input())

    flag = True
    simple = True

    if n < 24:
        flag = False
        break
    else:
        for i in range(2, int(math.sqrt(n))):
            if n % i == 0:
                simple = False
                break

    if flag is False or simple is True:
        print('NO')
    else:
        for i in range(2, int(n // 4)):
            if n % i == 0:
                a = i
                n = int(n / i)

                for j in range(a + 1, int(n // 2)):
                    if n % j == 0:
                        b = j
                        c = int(n / j)

                        if c != b and a != c:
                            print('YES')
                            print(a, b, c)
                            flag = True
                            break
                        else:
                            flag = False

                    else:
                        flag = False

        if flag is False:
            print('NO')


import math

for _ in range(int(input())):
    n = int(input())

    flag = False

    for i in range(2, int(math.sqrt(n))):
        if n % i == 0:
            a = i
            n = n / i

            for j in range(a + 1, int(math.sqrt(n))):
                if n % j == 0:
                    b = j
                    c = int(n / j)

                    if c != b and a != c:
                        print('YES')
                        print(a, b, c)
                        flag = True
                        break
        if flag is True:
            break

    if flag is False:
        print('NO')


import math

for _ in range(int(input())):
    n = int(input())

    flag = False

    if n < 24:
        print('NO')
    elif n == 24:
        print('YES')
        print(2, 3, 4)
    else:

        for i in range(2, int(math.sqrt(n)) + 1):
            if n % i == 0:
                a = i
                n = n / i

                for j in range(a + 1, int(math.sqrt(n)) + 1):
                    if n % j == 0:
                        b = j
                        c = int(n / j)

                        if c != b and a != c:
                            print('YES')
                            print(a, b, c)
                            flag = True
                            break
            if flag is True:
                break

        if flag is False:
            print('NO')


for _ in range(int(input())):
    n=nn=int(input())
    l1=[]; i=2
    while len(l1)<2 and i*i<=nn:
        if n%i==0: l1.append(i); n//=i
        i+=1
    if len(l1)<2 or l1[1]==n or l1[0]==n: print("NO")
    else: print("YES"); print(l1[0],l1[1],n)


for _ in range(int(input())):
    n=nn=int(input())
    l1=[]; i=2
    while len(l1)<2 and i*i<=nn:
        if n%i==0: l1.append(i); n//=i
        i+=1
    if len(l1)<2 or l1[1]==n: print("NO")
    else: print("YES"); print(l1[0],l1[1],n)


for _ in range(int(input())):
    n=int(input())
    l1=[]; i=2
    while len(l1)<2 and i*i<n:
        if n%i==0: l1.append(i); n//=i
        i+=1
    if len(l1)==2: print("YES"); print(*l1,n)
    else: print("NO")


ans=""
for _ in range(int(input())):
    n=nn=int(input())
    l1=[]; i=2
    while len(l1)<2 and i*i<=nn:
        if n%i==0: l1.append(i); n//=i
        i+=1
    if len(l1)<2 or l1[1]==n or l1[0]==n: ans+="NO\n"
    else: ans+="YES\n"; ans+=f"{l1[0]} {l1[1]} {n}\n"
print(ans)


ans=""
for _ in range(int(input())):
    n=int(input())
    l1=[]; i=2
    while len(l1)<2 and i*i<n:
        if n%i==0: l1.append(i); n//=i
        i+=1
    if len(l1)==2: ans+="YES\n"; ans+=f"{l1[0]} {l1[1]} {n}\n"
    else: ans+="NO\n"
print(ans)


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        print("YES")
        print(2, 5, int(n/10), sep=" ")
    else:
        result_found = False
        for a in range(2, int(n/12)):
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2)))
            for b in range(a + 1, max_b):
                result_found = n % (a*b) == 0
                if result_found:
                    c = int(n / (a*b))
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))

        divisors.pop(0)
        acceptable_divisors = [i for i in divisors if i <= n/2]
        pos_combinations = [tuple(x) for x in combinations(acceptable_divisors, 3)]

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))

        if not match_found:
            print("NO")

    else:
        break


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))

        divisors.pop(0)
        acceptable_divisors = [i for i in divisors if i <= n/2]
        pos_combinations = [tuple(x) for x in combinations(acceptable_divisors, 3)]

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))
            if result > n:
                break

        if not match_found:
            print("NO")

    else:
        break


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        a = 2
        n_div_10 = int(n/10)
        b = min(5, n_div_10)
        c = max(5, n_div_10)
        if b != c:
            print("YES")
            print(a, b, c, sep=" ")
        else:
            print("NO")
    else:
        result_found = False
        for a in range(2, int(n/12) + 1):
            #print("a: ", a)
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2))) + 1
            for b in range(a + 1, max_b):
                #print("b: ", b)
                prod_ab = a * b
                c = int(n/prod_ab)
                #print("c: ", c)
                #print(( (n % prod_ab == 0) , (prod_ab != n) , (c != a) , (c != b)))
                result_found = (n % prod_ab == 0) and (prod_ab != n) and (c != a) and (c != b)
                #print(result_found)
                if result_found:
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        a = 2
        n_div_10 = int(n/10)
        b = min(5, n_div_10)
        c = max(5, n_div_10)
        if b != c:
            print("YES")
            print(a, b, c, sep=" ")
        else:
            print("NO")
    else:
        result_found = False
        max_a = int(n ** (1. / 3.)) + 1
        for a in range(2, max_a):
            #print("a: ", a)
            if not n % a == 0:
                continue
            max_b = int((int(n/a) + 1)**(1./2.)) + 1
            for b in range(a + 1, max_b):
                #print("b: ", b)
                prod_ab = a * b
                c = int(n/prod_ab)
                #print("c: ", c)
                #print(( (n % prod_ab == 0) , (prod_ab != n) , (c != a) , (c != b)))
                result_found = (n % prod_ab == 0) and (prod_ab != n) and (c != a) and (c != b)
                #print(result_found)
                if result_found:
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))

        if len(divisors) < 3:
            print("NO")
            continue

        #divisors.pop(0)
        #acceptable_divisors = [i for i in divisors if i 2]
        pos_combinations = [tuple(x) for x in combinations(divisors, 3)]

        if len(pos_combinations) == 0:
            print("NO")
            continue

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))

        if not match_found:
            print("NO")


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))
        divisors.pop(0)

        if len(divisors) < 3:
            print("NO")
            continue

        acceptable_divisors = [i for i in divisors if i <= n/6]
        divisors = None
        pos_combinations = [tuple(x) for x in combinations(acceptable_divisors, 3)]
        acceptable_divisors = None

        if len(pos_combinations) == 0:
            print("NO")
            continue

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))
                break
        comb = None
        pos_combinations = None
        if not match_found:
            print("NO")


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        a = 2
        n_div_10 = int(n/10)
        b = min(5, n_div_10)
        c = max(5, n_div_10)
        if b != c:
            print("YES")
            print(a, b, c, sep=" ")
        else:
            print("NO")
    else:
        result_found = False
        for a in range(2, int(n/12)):
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2)))
            for b in range(a + 1, max_b):
                prod_ab = a * b
                c = int(n/prod_ab)
                result_found = (n % prod_ab == 0) and (prod_ab != n) and (c != a) and (c != b)
                if result_found:
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


def compute_problem(n):
    if n % 10 == 0:
        a = 2
        n_div_10 = int(n/10)
        b = min(5, n_div_10)
        c = max(5, n_div_10)
        if b != c:
            print("YES")
            print(a, b, c, sep=" ")
        else:
            print("NO")
    else:
        result_found = False
        for a in range(2, int(n/12)):
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2)))
            for b in range(a + 1, max_b):
                prod_ab = a * b
                c = int(n/prod_ab)
                result_found = (n % prod_ab == 0) and (prod_ab != n) and (c != a) and (c != b)
                if result_found:
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        print("YES")
        print(2, 5, int(n/10), sep=" ")
    else:
        result_found = False
        for a in range(2, int(n/12)):
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2)))
            for b in range(a + 1, max_b):
                prod_ab = a * b
                c = int(n/prod_ab)
                result_found = (n % prod_ab == 0) and (prod_ab != n) and (c != a) and (c != b)
                if result_found:
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))

        if len(divisors) < 3:
            print("NO")
            continue

        divisors.pop(0)
        acceptable_divisors = [i for i in divisors if i <= n/2]
        pos_combinations = [tuple(x) for x in combinations(acceptable_divisors, 3)]

        if len(pos_combinations) == 0:
            print("NO")
            continue

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))

        if not match_found:
            print("NO")


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))
        divisors.pop(0)

        if len(divisors) < 3:
            print("NO")
            continue

        acceptable_divisors = [i for i in divisors if i <= n/4]
        pos_combinations = [tuple(x) for x in combinations(divisors, 3)]

        if len(pos_combinations) == 0:
            print("NO")
            continue

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))
                break

        if not match_found:
            print("NO")


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))
        divisors.pop(0)

        if len(divisors) < 3:
            print("NO")
            continue

        #acceptable_divisors = [i for i in divisors if i 2]
        pos_combinations = [tuple(x) for x in combinations(divisors, 3)]

        if len(pos_combinations) == 0:
            print("NO")
            continue

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))

        if not match_found:
            print("NO")


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        print("YES")
        print(2, 5, int(n/10), sep=" ")
    else:
        result_found = False
        for a in range(2, int(n/12)):
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2)))
            for b in range(a + 1, max_b):
                result_found = n % (a*b) == 0
                if result_found:
                    c = n / (a*b)
                    print("YES")
                    print(a, b, c, sep=" ")
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


import math
from itertools import combinations

def divisor_generator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(int(n / i))
    for divisor in reversed(large_divisors):
        yield divisor

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        n = int(test_case)
        divisors = list(divisor_generator(n))

        divisors.pop(0)
        acceptable_divisors = [i for i in divisors if i <= n/4]
        pos_combinations = [tuple(x) for x in combinations(acceptable_divisors, 3)]

        match_found = False
        for comb in pos_combinations:
            result = comb[0]*comb[1]*comb[2]
            if result == n:
                match_found = True
                print("YES")
                print(' '.join(map(str, comb)))
            if result > n:
                break

        if not match_found:
            print("NO")

    else:
        break


def compute_problem(n):
    if n < 24:
        print("NO")
    elif n % 10 == 0:
        print("YES")
        print(2, 5, int(n/10), sep=" ")
    else:
        result_found = False
        for a in range(2, int(n/12)):
            if not n % a == 0:
                continue
            max_b = int(n/(a * (a + 2)))
            for b in range(a + 1, max_b):
                if not n % a*b == 0:
                    continue
                max_c = int(n / (a * (a + 1)))
                for c in range(b + 1, max_c):
                    result_found = (a * b * c == n)
                    if result_found:
                        print("YES")
                        print(a, b, c, sep=" ")
                        break
                if result_found:
                    break
            if result_found:
                break
        if not result_found:
            print("NO")

num_tests = int(input())

for test_num in range(0, num_tests):
    test_case = input()
    if test_case:
        aim_num = int(test_case)
        compute_problem(aim_num)


def pm(n):
    arr = []
    while(n%2==0):
        arr.append(2)
        n//=2
    for  i in range(3,int(pow(n,0.5))+1,2):
        while n%i==0:
            arr.append(i)
            n//=i
    if n>2:
        arr.append(n)
    return arr

tc = int(input())
for ii in range(tc):
    n = int(input())
    arr = pm(n)
    a = arr[0]
    b = 1
    c = 1
    index = 0
    for i in range(1,len(arr)):
        b*=arr[i]
        if b!=a:
            index = i
            break
    for j in range(index+1,len(arr)):
        c*=arr[j]

    if a!=b and b!=c and a!=c and a!=1 and b!=1 and c!=1:
        print("YES")
        print(a,b,c)
    else:
        print("NO")


def pm(n):
    arr = []
    while(n%2==0):
        arr.append(2)
        n//=2
    for  i in range(3,int(pow(n,0.5))+2,2):
        while n%i==0:
            arr.append(i)
            n//=i
    if n>2:
        arr.append(n)
    return arr

tc = int(input())
for ii in range(tc):
    n = int(input())
    arr = pm(n)
    a = arr[0]
    b = 1
    c = 1
    index = 0
    for i in range(1,len(arr)):
        b*=arr[i]
        if b!=a:
            index = i
            break
    for j in range(index+1,len(arr)):
        c*=arr[j]
        if c!=a and c!=b:
            break

    if a!=b!=c and a!=1 and b!=1 and c!=1:
        print("YES")
        print(a,b,c)
    else:
        print("NO")


def pm(n):
    arr = []
    while(n%2==0):
        arr.append(2)
        n//=2
    for  i in range(3,int(pow(n,0.5))+2,2):
        while n%i==0:
            arr.append(i)
            n//=i
    if n>2:
        arr.append(n)
    return arr

tc = int(input())
for ii in range(tc):
    n = int(input())
    arr = pm(n)
    a = arr[0]
    b = 1
    c = 1
    index = 0
    for i in range(1,len(arr)):
        b*=arr[i]
        if b!=a:
            index = i
            break
    for j in range(index+1,len(arr)):
        c*=arr[j]

    if a!=b!=c and a!=1 and b!=1 and c!=1:
        print("YES")
        print(a,b,c)
    else:
        print("NO")


def pm(n):
    arr = []
    while(n%2==0):
        arr.append(2)
        n//=2
    for  i in range(3,int(pow(n,0.5))+1,2):
        while n%i==0:
            arr.append(i)
            n//=i
    if n>2:
        arr.append(n)
    return arr

tc = int(input())
for ii in range(tc):
    n = int(input())
    arr = pm(n)
    a = arr[0]
    b = 1
    c = 1
    index = 0
    for i in range(1,len(arr)):
        b*=arr[i]
        if b!=a:
            index = i
            break
    for j in range(index+1,len(arr)):
        c*=arr[j]

    if a!=b!=c and a!=1 and b!=1 and c!=1:
        print("YES")
        print(a,b,c)
    else:
        print("NO")


def pm(n):
    arr = []
    while(n%2==0):
        arr.append(2)
        n//=2
    for  i in range(3,int(pow(n,0.5))+2,2):
        while n%i==0:
            arr.append(i)
            n//=i
    if n>2:
        arr.append(n)
    return arr

tc = int(input())
for i in range(tc):
    n = int(input())
    arr = pm(n)
    if len(arr)>=3 and arr[0]!=arr[1]!=arr[2]:
        print("YES")
        print(arr[0],arr[1],arr[2])
    elif len(arr)<3:
        print("NO")
    else:
        i = 0
        a = 1
        b = 1
        c = 1
        a = arr[0]
        for j in range(1,len(arr)):
            if b*arr[j]==a:
                b*=arr[j]
                i=j
            else:
                b*=arr[j]
                i+=2
                break

        for k in range(i,len(arr)):
            if c*arr[k]==b or c*arr[k]==a:
                c*=arr[k]
            else:
                c*=arr[k]

        if a!=b!=c and a!=1 and b!=1 and c!=1:
            print("YES")
            print(a,b,c)
        else:
            print("NO")


from math import ceil
def find(n,p,ans):
    for i in range(ceil(n**(1/(p-1)))+1,1,-1):
        if n%i==0:
            if p==3:
                ans+=[find(n//i,2,[i])]
            elif p==2 and n//i>1:
                ans+=[(n//i),i]
                return ans
    return ans

for i in range(int(input())):
    n=int(input())
    flag=1
    for i in find(n,3,[]):
        if len(set(i))==3:
            print("YES")
            print(*i,sep=" ")
            flag=0
            break
    if flag:
        print("NO")


from math import ceil
def find(n,p,ans):
    for i in range(2,ceil(n**(1/p))+1,1):
        if n%i==0:
            if p==3:
                ans+=find(n//i,2,[i])
                if len(set(ans))==3:
                    return ans
                ans=[]
            elif p==2 and n//i>1:
                new=ans+[(n//i),i]
                if len(set(new))==3:
                    return new
    return ans

for i in range(int(input())):
    n=int(input())
    k=find(n,3,[])
    if len(k)==3:
        print("YES")
        print(*k,sep=" ")
    else:
        print("NO")


from math import ceil
def find(n,p,ans):
    for i in range(2,ceil(n**(1/p))+1,1):
        if n%i==0:
            if p==3:
                ans+=find(n//i,2,[i])
                if len(ans)==3:
                    return ans
                ans=[]
            elif p==2 and n//i>1:
                new=ans+[(n//i),i]
                if len(set(new))==3:
                    return new
    return ans

for i in range(int(input())):
    n=int(input())
    k=find(n,3,[])
    if len(k)==3:
        print("YES")
        print(*k,sep=" ")
    else:
        print("NO")


from math import ceil
def find(n,p,ans):
    for i in range(ceil(n**(1/p))+1,1,-1):
        if n%i==0:
            if p==3:
                ans+=[find(n//i,2,[i])]
            elif p==2:
                ans+=[(n//i),i]
                return ans
    return ans

for i in range(int(input())):
    n=int(input())
    flag=1
    for i in find(n,3,[]):
        if len(set(i))==3:
            print("YES")
            print(*i,sep=" ")
            flag=0
            break
    if flag:
        print("NO")


from math import ceil
def find(n,p,ans):
    for i in range(ceil(n**(1/p))+1,1,-1):
        if n%i==0:
            if p==3:
                ans+=[find(n//i,2,[i])]
            elif p==2 and n//i>1:
                ans+=[(n//i),i]
                return ans
    return ans

for i in range(int(input())):
    n=int(input())
    flag=1
    for i in find(n,3,[]):
        if len(set(i))==3:
            print("YES")
            print(*i,sep=" ")
            flag=0
            break
    if flag:
        print("NO")


for _ in " "*int(input()):
    n=int(input());a=[];i=2
    while(len(a)<2 and i*i<n):
        if n%i==0:n=n//i;a.append(i)
        i+=1
    if len(a)==2 and n not in a:print("YES");print(n,*a)
    else:print("NO")


for _ in " "*int(input()):
    k=int(input());a=[];i=2;z=k//2
    while(k!=1 and i<=z):
        if k%i==0:k=k//i;a+=[i]
        i+=1
        if len(a)==2 and k not in a:a+=[k];break
    if len(a)==3:print("YES"),print(*a)
    else:print("NO")


for _ in " "*int(input()):
    k=int(input());a=[];i=k//2;z=[]
    while(i>1):
        if k%i==0:a+=[k//i,i];break
        else:i-=1
    if len(a)==0:print("NO")
    else:
        i=a[0]+1
        while(a[1]!=1 and i<=a[1]//2):
            if (a[1]%i==0 and i!=a[0]):z=z+[i,a[1]//i];break
            else:i+=1
        if len(z)==0 :print("NO")
        elif len(set(z))<2:print("NO")
        elif len(set([a[0]]+z))<3:print("N0")
        else:print("YES");print(a[0],z[0],z[1])


for _ in " "*int(input()):
    k=int(input());a=[];i=2;z=k//2
    while(k!=1 and i<=z):
        if k%i==0:k=k//i;a+=[i]
        i+=1
        if len(a)==2:a+=[k];break
    if len(a)==3:print("YES"),print(*a)
    else:print("NO")


for _ in " "*int(input()):
    k=int(input());a=[];i=k//2;z=[]
    while(i>1):
        if k%i==0:a+=[k//i,i];break
        else:i-=1
    if len(a)==0:print("NO")
    else:
        i=a[0]+1
        while(a[1]!=1 and i<=a[1]//2):
            if a[1]%i==0:z=z+[i,a[1]//i];break
            else:i+=1
        if len(z)==0 :print("NO")
        elif len(set(z))<2:print("NO")
        else:print("YES");print(a[0],z[0],z[1])


for _ in " "*int(input()):
    k=int(input());a=[];i=k//2;z=[]
    while(i>1):
        if k%i==0:a+=[k//i,i];break
        else:i-=1
    if len(a)==0:print("NO")
    else:
        i=a[0]+1
        while(a[1]!=1 and i<=a[1]//2):
            if a[1]%i==0:z=z+[i,a[1]//i];break
            else:i+=1
        if len(z)==0 :print("NO")
        elif len(set(z))<2:print("NO")
        elif len(set([a[0]]+z))<3:print("N0")
        else:print("YES");print(a[0],z[0],z[1])


for _ in " "*int(input()):
    k=int(input());a=[];i=2;z=k//2
    while(k!=1 and i<=z):
        if k%i==0:k=k//i;a+=[i]
        i+=1
        if len(a)==2 and (k not in a and k!=1):a+=[k];break
    if len(a)==3:print("YES"),print(*a)
    else:print("NO")


for _ in " "*int(input()):
    k=int(input());a=[];i=2;z=k//2
    while(k!=1 and i<=z):
        if k%i==0:k=k//i;a+=[i]
        i+=1
        if len(a)==3:break
    if len(a)==3:print("YES"),print(*a)
    else:print("NO")


rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]

def fact(n):
    res=[]
    for i in range(2, int(n**.5)+1):
        if n%i==0:
            res.append(i)
            res.append(n//i)
    if (int(n**.5)**2==n):
        res.pop()
    return res

def sol():
    n=rri()
    f=fact(n)
    #print(f)
    if (len(f)<3):
        print("NO")
        return
    f.sort()
    a=f[0]
    d=n//a
    for i in range(1, len(f)):
        for j in range(i+1, len(f)):
            if f[i]*f[j]==d:
                print("YES")
                print (a, f[i], f[j])
                return
    print("NO")
    return

t=rri()
for _ in range(t):
    #a,b,c=rrm()
    sol()
    #print(ans)


rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]

def fact(n):
    res=[]
    for i in range(2, int(n**.5)):
        if n%i==0:
            res.append(i)
            res.append(n//i)
    if (int(n**.5)**2==n):
        res.append(int(n**.5))
    return res

def sol():
    n=rri()
    f=fact(n)
    if (len(f)<3):
        print("NO")
        return
    f.sort()
    a=f[0]
    d=n//a
    for i in range(1, len(f)):
        for j in range(i+1, len(f)):
            if f[i]*f[j]==d:
                print("YES")
                print (a, f[i], f[j])
                return
    print("NO")
    return

t=rri()
for _ in range(t):
    #a,b,c=rrm()
    sol()
    #print(ans)


rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]

def fact(n):
    res=[]
    for i in range(2, int(n**.5)):
        if n%i==0:
            res.append(i)
            res.append(n//i)
    if (int(n**.5)**2==n):
        res.append(int(n**.5))
    return res

def sol():
    n=rri()
    f=fact(n)
    if (len(f)<3):
        return "NO"
    f.sort()
    a=f[0]
    d=n//a
    for i in range(1, len(f)):
        for j in range(i+1, len(f)):
            if f[i]*f[j]==d:
                print("YES")
                return (a, f[i], f[j])
    return "NO"

t=rri()
for _ in range(t):
    #a,b,c=rrm()
    ans=sol()
    print(ans)


rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]

def fact(n):
    res=[]
    for i in range(2, int(n**.5)+1):
        if n%i==0:
            res.append(i)
            res.append(n//i)
    if (int(n**.5)**2==n):
        res.pop()
    return res

def sol():
    n=rri()
    f=fact(n)
    print(f)
    if (len(f)<3):
        print("NO")
        return
    f.sort()
    a=f[0]
    d=n//a
    for i in range(1, len(f)):
        for j in range(i+1, len(f)):
            if f[i]*f[j]==d:
                print("YES")
                print (a, f[i], f[j])
                return
    print("NO")
    return

t=rri()
for _ in range(t):
    #a,b,c=rrm()
    sol()
    #print(ans)


rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]

def fact(n):
    res=[]
    for i in range(2, int(n**.5)+1):
        if n%i==0:
            res.append(i)
            res.append(n//i)
    if (int(n**.5)**2==n):
        res.pop()
    return res

def sol():
    n=rri()
    f=fact(n)
    #print(f)
    if (len(f)<3):
        print("NO")
        return
    f.sort()
    a=f[0]
    d=n//a
    b=f[1]
    n//=a
    if n%b==0 and n//b!=b:
        c=n//b
    else:
        print("NO")
        return
    print("YES")
    print(a, b, c)
    return

t=rri()
for _ in range(t):
    #a,b,c=rrm()
    sol()
    #print(ans)


import math

MAXN = 5000000
sieve = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
sieve[2] = True
primes = []

for i in range(MAXN):
    if sieve[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            sieve[j] = False

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return

t = int(input())
while t > 0:
    n = int(input())
    if is_prime(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) == 3:
            a, b, c = d
        else:
            d.extend([1,1,1,1])
            a, b, x, c = d[0], d[1]*d[2], d[3:], 1
            for i in x:
                c *= i

        if a!=b and a!=c and b!=c and not (1 in [a, b, c]):
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math

MAXN = 8000000
sieve = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
sieve[2] = True
primes = []

for i in range(MAXN):
    if sieve[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            sieve[j] = False

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return

t = int(input())
while t > 0:
    n = int(input())
    if is_prime(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) == 3:
            a, b, c = d
        else:
            d.extend([1,1,1,1])
            a, b, x, c = d[0], d[1]*d[2], d[3:], 1
            for i in x:
                c *= i

        if a!=b and a!=c and b!=c and not (1 in [a, b, c]):
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math
import sys

# sys.stdin = open("input.txt", "r")

MAXN = 800000
sieve = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
sieve[2] = True
primes = []

for i in range(MAXN):
    if sieve[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            sieve[j] = False

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return

def pwr(x, n):
    if n == 0:
        return 1
    if n == 1:
        return x
    if n % 2 != 0:
        return x * pwr(x, n - 1)
    y = pwr(x, n // 2)
    return y*y

def test(a, b, c):
    return a!=b and a!=c and b!=c and not (1 in [a, b, c])

t = int(input())
while t > 0:
    n = int(input())
    if is_prime(n):
        print("NO")
    else:
        s = set()
        d1 = []
        f = {}
        n_cpy = n
        for p in primes:
            while n_cpy % p == 0:
                s.add(p)
                d1.append(p)
                if not p in f.keys():
                    f[p] = 1
                else:
                    f[p] += 1
                n_cpy /= p

        d = list(s)
        if len(d) >= 2:
            a, b = pwr(d[0], f[d[0]]), pwr(d[1], f[d[1]])
            c = int(n // (a * b))
            if c == 1:
                n_c = 1
                if f[d[0]] > 1:
                    n_c *= pwr(d[0], f[d[0]] - 1)
                    a = d[0]
                if f[d[1]] > 1:
                    n_c *= pwr(d[1], f[d[1]] - 1)
                    b = d[1]
                c = n_c

            if test(a, b, c):
                print("YES")
                print(f"{a} {b} {c}")
            else:
                print("NO")
        else:
            if len(d1) >= 3:
                d1.extend([1,1,1,1])
                a, b, x, c = d1[0], d1[1]*d1[2], d1[3:], 1
                for i in x:
                    c *= i
                if test(a, b, c):
                    print("YES")
                    print(f"{a} {b} {c}")
                else:
                    print("NO")
            else:
                print("NO")

    t = t - 1


import math

MAXN = 600000
sieve = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
sieve[2] = True
primes = []

for i in range(MAXN):
    if sieve[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            sieve[j] = False

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return True

t = int(input())
while t > 0:
    n = int(input())
    if is_prime(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) == 3:
            a, b, c = d
        else:
            d.append(1)
            a, b, x, c = d[0], d[1]*d[2], d[3:], 1
            for i in x:
                c *= i

        if a!=b and a!=c and b!=c and not (1 in [a, b, c]):
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math

MAXN = 600000
is_prime = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
is_prime[2] = True
primes = []

for i in range(MAXN):
    if is_prime[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            is_prime[j] = False

def isp(n):
    if n == 2:
        return True
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return True

t = int(input())
while t > 0:
    n = int(input())
    if isp(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) > 3:
            a = d[0]
            b = d[1]*d[2]
            if len(d) == 4:
                c = d[3]
            else:
                c = 1
                for j in d[3:]:
                    c *= j
        else:
            a, b, c = d

        if a!=b and a!=c and b!=c:
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math

MAXN = 600000
is_prime = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
is_prime[2] = True
primes = []

for i in range(MAXN):
    if is_prime[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            is_prime[j] = False

def isp(n):
    if n == 2:
        return True
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False"""  """
    return True

t = int(input())
while t > 0:
    n = int(input())
    if isp(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) > 3:
            a = d[0]
            b = d[1]*d[2]
            if len(d) == 4:
                c = d[3]
            else:
                c = 1
                for j in d[3:]:
                    c *= j
        else:
            a, b, c = d

        if a!=b and a!=c and b!=c:
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math

MAXN = 600000
sieve = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
sieve[2] = True
primes = []

for i in range(MAXN):
    if sieve[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            sieve[j] = False

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return True

t = int(input())
while t > 0:
    n = int(input())
    if is_prime(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) == 3:
            a, b, c = d
        else:
            d.append(1)
            a, b, x, c = d[0], d[1]*d[2], d[3:], 1
            for i in x:
                c *= i

        if a!=b and a!=c and b!=c:
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math

MAXN = 32000
is_prime = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
is_prime[2] = True
primes = []

for i in range(MAXN):
    if is_prime[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            is_prime[j] = False

def isp(n):
    if n == 2:
        return True
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return True

t = int(input())
while t > 0:
    n = int(input())
    if isp(n):
        print("NO")
    else:
        d = []
        for p in primes:
            while n % p == 0:
                d.append(p)
                n /= p

        if len(d) > 3:
            a = d[0]
            b = d[1]*d[2]
            if len(d) == 4:
                c = d[3]
            else:
                c = 1
                for j in d[3:]:
                    c *= j
        else:
            a, b, c = d

        if a!=b and a!=c and b!=c:
            print("YES")
            print(f"{a} {b} {c}")
        else:
            print("NO")

    t = t - 1


import math

MAXN = 100000
sieve = [True if (i > 1 and i % 2 != 0) else False for i in range(MAXN)]
sieve[2] = True
primes = []

for i in range(MAXN):
    if sieve[i]:
        primes.append(i)
        for j in range(i+i, MAXN, i):
            sieve[j] = False

def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(3, int(math.sqrt(n) + 1)):
        if n % i == 0:
            return False
    return

def pwr(x, n):
    if n == 0:
        return 1
    if n == 1:
        return x
    if n % 2 != 0:
        return x * pwr(x, n - 1)
    y = pwr(x, n // 2)
    return y*y

def test(a, b, c):
    return a!=b and a!=c and b!=c and not (1 in [a, b, c])

t = int(input())
while t > 0:
    n = int(input())
    if is_prime(n):
        print("NO")
    else:
        s = set()
        d1 = []
        f = {}
        n_cpy = n
        for p in primes:
            while n_cpy % p == 0:
                s.add(p)
                d1.append(p)
                if not p in f.keys():
                    f[p] = 1
                else:
                    f[p] += 1
                n_cpy /= p

        d = list(s)
        if len(d) >= 2:
            a, b = pwr(d[0], f[d[0]]), pwr(d[1], f[d[1]])
            c = int(n // (a * b))
            if c == 1:
                n_c = 1
                if f[d[0]] > 1:
                    n_c *= pwr(d[0], f[d[0]] - 1)
                    a = d[0]
                if f[d[1]] > 1:
                    n_c *= pwr(d[1], f[d[1]] - 1)
                    b = d[1]
                c = n_c

            if test(a, b, c):
                print("YES")
                print(f"{a} {b} {c}")
            else:
                print("NO")
        else:
            if len(d1) >= 3:
                d1.extend([1,1,1,1])
                a, b, x, c = d1[0], d1[1]*d1[2], d1[3:], 1
                for i in x:
                    c *= i
                if test(a, b, c):
                    print("YES")
                    print(f"{a} {b} {c}")
                else:
                    print("NO")
            else:
                print("NO")

    t = t - 1


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define pii pair<int,int>
typedef long long ll;
const int mod = 1000000007;
const int MAXN=100005;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
int num[100005];
map<int,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

//    int ans=INF;
    int ans=0;
    int b1,q,l,m;
    scandd(b1,q);
    scandd(l,m);
    for(int i=1;i<=m;++i)
    {
        int x;
        scand(x);
        ma[x]=1;
    }
    if(q==1||q==-1)
    {
        if(l<abs(b1)||ma.count(b1))
        {
            return 0*printf("0");
        }
        else return 0*printf("inf");
    }
    ll now = b1;
    while(abs(now)<=l)
    {
        ans++;
        if(ma.count(now))ans--;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if((q==1||q==-1)&&abs(b)<=l)return puts("inf");
    if(!q)
    {
        if(ma.count(b)||abs(b)>l)return puts("0");
        if(!ma.count(0))return puts("inf");
         return puts("1");
    }
    if(!b)
    {
        if(ma.count(0))return puts("0");
        else return puts("inf");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if((q==1||q==-1)&&abs(b)<=l)return puts("inf");
    if(!q)
    {
        if(!ma.count(0))return puts("inf");
        if(ma.count(b))return puts("0");
        else return puts("1");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if(q==1&&abs(b)<=l)return puts("inf");
    if(q==-1)
    {
        if(ma.count(b)&&ma.count(-b)||abs(b)>l)return puts("0");
        else return puts("inf");
    }
    if(!q)
    {
        if(!ma.count(0)&&abs(b)<=l)return puts("inf");
        if(ma.count(b)||abs(b)>l)return puts("0");
        return puts("1");
    }
    if(!b)
    {
        if(ma.count(0))return puts("0");
        else return puts("inf");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define pii pair<int,int>
typedef long long ll;
const int mod = 1000000007;
const int MAXN=100005;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
int bad[100005];
int badturn[100005];
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

//    int ans=INF;
    int ans=0;
    int b1,q,l,m;
    scandd(b1,q);
    scandd(l,m);
    for(int i=1;i<=m;++i)
    {
        scand(bad[i]);
    }
    sort(bad+1,bad+1+m);
    for(int i=1;i<=m;++i)badturn[i]=bad[m-i+1];
    int res=1;
    while(bad[res]<b1)res++;
    if(q==1||q==-1)
    {
        if(l<abs(b1)||bad[res]==b1)
        {
            return 0*printf("0");
        }
        else return 0*printf("inf");
    }
    ll now = b1;
    int resturn = m;res=1;
    while(abs(now)<=l)
    {
        ans++;
        bool op=0;
        while(resturn>1&&badturn[resturn]>now)resturn--;
        if(badturn[resturn]==now)ans--,op=1;
        if(!op)
        {
            while(res<m&&bad[res]<now)res++;
            if(bad[res]==now)ans--;
        }
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if(q==1&&abs(b)<=l)return puts("inf");
    if(q==-1)
    {
        if(ma.count(b)&&ma.count(-b)||abs(b)>l)return puts("0");
        else return puts("inf");
    }
    if(!q)
    {
        if(ma.count(b)||abs(b)>l)return puts("0");
        if(!ma.count(0))return puts("inf");
         return puts("1");
    }
    if(!b)
    {
        if(ma.count(0))return puts("0");
        else return puts("inf");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if((q==1||q==-1)&&abs(b)<=l)return puts("inf");
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if(q==1&&abs(b)<=l)return puts("inf");
    if(q==-1)
    {
        if(ma.count(b)&&ma.count(-b)||abs(b)>l)return puts("0");
        else return puts("inf");
    }
    if(!q)
    {
        if(!ma.count(0))return puts("inf");
        if(ma.count(b)||abs(b)>l)return puts("0");
        return puts("1");
    }
    if(!b)
    {
        if(ma.count(0))return puts("0");
        else return puts("inf");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if(q==1&&abs(b)<=l)return puts("inf");
    if(q==-1)
    {
        if(ma.count(b)&&ma.count(-b)||abs(b)>l)return puts("0");
        else return puts("inf");
    }
    if(!q)
    {
        if(!ma.count(0)&&abs(b)<l)return puts("inf");
        if(ma.count(b)||abs(b)>l)return puts("0");
        return puts("1");
    }
    if(!b)
    {
        if(ma.count(0))return puts("0");
        else return puts("inf");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if(q==1&&abs(b)<=l)return puts("inf");
    if(q==-1)
    {
        if(ma.count(b)&&ma.count(-b)||abs(b)>m)return puts("0");
        else return puts("inf");
    }
    if(!q)
    {
        if(ma.count(b)||abs(b)>l)return puts("0");
        if(!ma.count(0))return puts("inf");
         return puts("1");
    }
    if(!b)
    {
        if(ma.count(0))return puts("0");
        else return puts("inf");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scandd(n,m) scanf("%d%d",&n,&m)
#define scanddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define scanlld(n) scanf("%lld",&n)
#define scanlldd(n,m) scanf("%lld%lld",&n,&m)
#define scanllddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define scanlf(n) scanf("%lf",&n)
#define scanlff(n,m) scanf("%lf%lf",&n,&m)
#define scanlfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define scans(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define llans() printf("%lld",ans)
#define llanss() printf("%lld ",ans)
#define llansn() printf("%lld\n",ans)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REA(i,qwe,ewr) for(int i=qwe;i<=ewr;++i)
#define RER(i,qwe,ewr) for(int i=qwe;i>=ewr;--i)
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
typedef long long ll;
inline int mul_mod(int a, int b, int mo)
{
    int ret;
    __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret):"a"(a),"b"(b),"c"(mo));
    return ret;
}
const int mod = 1000000007;
const double eps=1e-9;
const int INF=0x3f3f3f3f;
const int MAXN=200005;

map<ll,bool>ma;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    ll b,q,l,m;
    scanlldd(b,q);
    scanlldd(l,m);
    for(int i=1;i<=m;++i)
    {
        ll x;
        scanlld(x);
        ma[x] =1;
    }
    if(q==1&&ma.count(b))return puts("0");
    if((q==1||q==-1)&&abs(b)<=l)return puts("inf");
    if(!q)
    {
        if(ma.count(b)||abs(b)>l)return puts("0");
        if(!ma.count(0))return puts("inf");
         return puts("1");
    }
    int ans =0;
    ll now = b;
    while(abs(now)<=l)
    {
        if(!ma.count(now))++ans;
        now*=q;
    }
    ans();
    return 0;
}


#include<iostream>
#include<cmath>
#include<set>
using namespace std;
set<long long>c;
int main()
{
    long long b1,q,l,m;
    while(cin>>b1>>q>>l>>m)
    {
        long long x,cnt=0;
        while(m--)
        {
            cin>>x;
            c.insert(x);
        }
        if(l<abs(b1))
        {
            cout<<0<<endl;
            continue;
        }
        if(b1==0)
        {
            if(c.find(0)!=c.end())
              cout<<0<<endl;
            else
              cout<<"inf"<<endl;
            continue;
        }
        if(q==-1)
        {
            if(c.find(b1)!=c.end()&&c.find(-b1)!=c.end())
              cout<<0<<endl;
            else
              cout<<"inf"<<endl;
        }
        else if(q==0)
        {
            if(c.find(0)!=c.end())
            {
                if(c.find(b1)!=c.end())
                  cout<<0<<endl;
                else
                  cout<<1<<endl;
            }
            else
              cout<<"inf"<<endl;
        }
        else if(q==1)
        {
            if(c.find(b1)!=c.end())
              cout<<0<<endl;
            else
              cout<<"inf"<<endl;
        }
        else
        {
            while(l>=abs(b1))
            {
                if(c.find(b1)==c.end())
                  cnt++;
                b1*=q;
            }
            cout<<cnt<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b,q,l,m,i;
	while(cin>>b>>q>>l>>m)
	{
		int a[m],s=0,p=0;
		for(i=0;i<m;i++)
		{
			cin>>a[i];
		}
		if(q==1||b==0)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					cout<<0<<endl;
					goto P;
				}
				else
				{
				    cout<<"inf"<<endl;
				    goto P;
				}
			}
		}
		if(q==0)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i]||a[i]==0)
				{
					cout<<0<<endl;
					goto P;
				}
				else
				{
					cout<<1<<endl;
					goto P;
				}
			}
		}
		while(b<l)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					p++;
					break;
				}
				else
				if(i==m-1)
				s++;
			}
			b=b*q;
		}
		if(p==0)
		cout<<"inf"<<endl;
		else
		cout<<s<<endl;
		P:continue;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b,q,l,m,i;
	while(cin>>b>>q>>l>>m)
	{
		int a[m],s=0,p=0;
		for(i=0;i<m;i++)
		{
			cin>>a[i];
		}
		if(q==1||b==0)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					cout<<0<<endl;
					goto P;
				}
				else
				if(i==m-1)
				{
				    cout<<"inf"<<endl;
				    goto P;
				}
			}
		}
		if(q==0)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i]||a[i]==0)
				{
					cout<<0<<endl;
					goto P;
				}
				else
				if(i==m-1)
				{
					cout<<1<<endl;
					goto P;
				}
			}
		}
		if(q==-1)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i]||-b==a[i])
				{
					cout<<0<<endl;
					goto P;
				}
				else
				if(i==m-1)
				{
					cout<<1<<endl;
					goto P;
				}
			}
		}
		while(fabs(b)<l)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					p++;
					break;
				}
				else
				if(i==m-1)
				s++;
			}
			b=b*q;
		}
		if(p==0)
		cout<<"inf"<<endl;
		else
		cout<<s<<endl;
		P:continue;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
map<int, int>a;
int main() {
    long long int b1, q, l;
    int m;
    scanf("%lld%lld%lld%d", &b1, &q, &l, &m);
    for(int i = 0, x; i < m; i++) {
        scanf("%d", &x);
        a[x] = 1;
    }
    if(b1 == 0) {
        if(a[0]) printf("0\n");
        else printf("inf");
    } else if(q == 0) {
        if(a[0] || abs(b1) > l) {
            if(a[b1] || abs(b1) > l) printf("0\n");
            else printf("1\n");
        } else printf("inf\n");
    } else if(q == 1) {
        if(abs(b1) > l || a[b1]) printf("0\n");
        else printf("inf\n");
    } else if(q == -1) {
        if((a[-b1] && a[b1]) || abs(b1) > l) printf("0\n");
        else printf("inf\n");
    } else {
        int cnt = 0;
        while(abs(b1) <= l) {
            if(!a[b1]) cnt++;
            b1 *= q;
        }
        printf("%d\n", cnt);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b,q,l,m,i;
	while(cin>>b>>q>>l>>m)
	{
		int a[m],s=0,p=0;
		for(i=0;i<m;i++)
		{
			cin>>a[i];
		}
		if(q==1||b==0)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					cout<<0<<endl;
					goto P;
				}
				else
				if(i==m-1)
				{
				    cout<<"inf"<<endl;
				    goto P;
				}
			}
		}
		if(q==0)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i]||a[i]==0)
				{
					cout<<0<<endl;
					goto P;
				}
				else
				if(i==m-1)
				{
					cout<<1<<endl;
					goto P;
				}
			}
		}
		while(b<l)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					p++;
					break;
				}
				else
				if(i==m-1)
				s++;
			}
			b=b*q;
		}
		if(p==0)
		cout<<"inf"<<endl;
		else
		cout<<s<<endl;
		P:continue;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b,q,l,m,i;
	while(cin>>b>>q>>l>>m)
	{
		int a[m],s=0,p=0;
		for(i=0;i<m;i++)
		{
			cin>>a[i];
		}
		if(q==1)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					cout<<0<<endl;
					goto P;
				}
				else
				{
				    cout<<"inf"<<endl;
				    goto P;
				}
			}
		}
		while(b<l)
		{
			for(i=0;i<m;i++)
			{
				if(b==a[i])
				{
					p++;
					break;
				}
				else
				if(i==m-1)
				s++;
			}
			b=b*q;
		}
		if(p==0)
		cout<<"inf"<<endl;
		else
		cout<<s<<endl;
		P:continue;
	}
	return 0;
}


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(arr.count(b)!=0) printf("0\n");
	else if(abs(q)==1) printf("inf\n");
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(abs(q)==1&&arr.count(b)!=0||abs(b)>l) printf("0\n");
	else if(abs(q)==1) printf("inf\n");
	else if(q==0){
		if(arr.count(0)!=0){
			if(arr.count(b)!=0) printf("0\n");
			else printf("1\n");
		}
		else printf("inf\n");
	}
	else if(b==0){
		if(arr.count(b)!=0) printf("0\n");
		else printf("inf\n");
	}
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(abs(q)==1&&arr.count(b)!=0||b>l) printf("0\n");
	else if(abs(q)==1) printf("inf\n");
	else if(q==0){
		if(arr.count(0)!=0){
			if(arr.count(b)!=0) printf("0\n");
			else printf("1\n");
		}
		else printf("inf\n");
	}
	else if(b==0){
		if(arr.count(b)!=0) printf("0\n");
		else printf("inf\n");
	}
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(arr.count(b)!=0) printf("0\n");
	else if(abs(q)==1||b==0) printf("inf\n");
	else if(q==0){
		if(arr.count(0)!=0) printf("1\n");
		else printf("inf\n");
	}
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(abs(q)==1&&arr.count(b)!=0||b>l) printf("0\n");
	else if(abs(q)==1||b==0) printf("inf\n");
	else if(q==0){
		if(arr.count(0)!=0) printf("1\n");
		else printf("inf\n");
	}
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(abs(q)==1&&arr.count(b*q)!=0||abs(b)>l) printf("0\n");
	else if(abs(q)==1) printf("inf\n");
	else if(q==0){
		if(arr.count(0)!=0){
			if(arr.count(b)!=0) printf("0\n");
			else printf("1\n");
		}
		else printf("inf\n");
	}
	else if(b==0){
		if(arr.count(b)!=0) printf("0\n");
		else printf("inf\n");
	}
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(arr.count(b)!=0) printf("0\n");
	else if(abs(q)==1||b==0||q==0) printf("inf\n");
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/


#include <bits/stdc++.h>

#define REP(i, a) for(int i = 0; i < a; i++)
#define RFOR(i,x,y) for(int i = x; i>= y; i--)
#define FOR(i,x,y) for (int i = x; i < y; i++)
#define ITFOR(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define VE vector <int>
#define mset(A,x) memset(A, x, sizeof A)
#define PB push_back
#define ones(x) __builtin_popcount(x)
#define cua(x) (x)*(x)
#define debug(x) cout <<#x << " = " << x << endl
#define adebug(x,n) cout <<#x<<endl; REP(i,n)cout<<x[i]<<char(i+1==n?10:32)
#define mdebug(x,m,n) cout <<#x<<endl; REP(i,m)REP(j,n)cout<<x[i][j]<<char(j+1==n?10:32)
#define LSOne(S) (S&(-S))

using namespace std;

#define ll long long
#define lli long long int
#define PI acos(-1.0)
#define ii pair<int,int>
#define inf_ll (((1LL<<62)-1)<<1)+1
#define inf_i (1<<30)-1

int main(){
	set<lli> arr;
	lli b,q,l,m,num,cnt=0; scanf("%lld %lld %lld %lld",&b,&q,&l,&m);
	REP(i,m){
		scanf("%lld",&num);
		arr.insert(num);
	}
	if(arr.count(b)!=0) printf("0\n");
	else if(abs(q)==1||b==0) printf("inf\n");
	else if(q==0){
		if(arr.count(0)!=0) printf("0\n");
		else printf("inf\n");
	}
	else {
		while(abs(b)<=l){
			if(arr.count(b)==0) cnt++;
			b*=q;
		}
		printf("%lld\n",cnt);
	}
  return 0;
}

/*
   freopen("input.txt", "r", stdin);
   freopen("out.txt", "w", stdout);
*/

/*
    fclose(stdin);
    fclose(stdout);
*/