You were strolling outside the restaurant at the end of the universe. On a metaspiral path you stumble upon a weird device which takes a three-digit number as input and processes it. The Hitchhiker's guide to the galaxy explains that it processes the input in the following manner: 
- Multiplies it with 13, followed by 11 and then 7          
- Outputs all the distinct three-digit numbers possible from the digits of the new number (each digit can only be used once)          
Your friend Zaphod is in a playful mood, and does the following with the device-           
- Given a three-digit positive number $K$, he feeds it to the device for processing.          
- He then takes the numbers it gives as output, and send each of them through the device and again collect all the numbers sent out.          
- Repeats the above step $N$ times.          
To test your wit, he challenges you to find the number of distinct 3-digit numbers which the device outputs over the $N$ steps. Can you?

-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, two integers $K, N$.

-----Output:-----
For each testcase, output a single integer denoting the number of distinct 3-digit numbers which the device outputs over the $N$ steps.

-----Constraints-----
- $1 \leq T \leq 1000$ 
- $5 \leq N \leq 10^9$ 
- Each digit of $K$ is non-zero           

-----Sample Input:-----
1

123 5         

-----Sample Output:-----
27

Starter code:

Solutions:
for _ in range(int(input())):
 k, n = input().split()

 while int(n) >= 5:
  print(len(set(k)) ** 3)
  break

for _ in range(int(input())):
 K,N = map(int, input().split())
 K=str(K)
 l=[int(d) for d in K]
 while N>=5:
  print(len(set(K))**3)
  break

# cook your dish here
try:
 from sys import stdin as si , stdout as so

 for _ in range(int(si.readline())):
  n , k = si.readline().split()
  a = set(n)
  so.write(str(len(a) ** 3) + '\n')
except:
 pass

for _ in range(int(input())):
 k,n=input().split()
 if k[0]==k[1] and k[1]==k[2]:
  print(1)
 elif k[0]!=k[1] and k[1]!=k[2] and k[0]!=k[2]:
  print(27)
 else:
  print(8)

for _ in range(int(input())):
 k,n=input().split()
 if k[0]==k[1] and k[1]==k[2]:
  print(1)
 elif k[0]!=k[1] and k[1]!=k[2] and k[0]!=k[2]:
  print(27)
 else:
  print(8)

from math import *
for _ in range(int(input())):
 k,n = map(str, input().split())
 n = int(n)
 p = len(set(list(k)))
 if p == 1:
  print(1)
 else:
  p = p**3
  x = 1
  y = 1
  flag = 0
  for i in range(n):
   if x > p:
    flag = 1
    break
   x += (y*2)
   y *= 2
  if flag == 0:
   print(x-y)
  else:
   print(p)

# cook your dish here
for _ in range(int(input())) :
 k,n=map(str,input().split())
 if k[0]==k[1]==k[2]:
  print(1)
 elif k[0]!=k[1] and k[0]!=k[2] and k[1]!=k[2] :
  print(27)
 else :
  print(8)

# cook your dish here
for i in range(int(input())):
 a = list(map(int, input().split()))
 l = list(map(int, str(a[0])))
 t = len(set(l))
 
 if t == 3:
  print("27")
 elif t == 2:
  print("8")
 else:
  print("1")

t = int(input())
while t:
 n, k = [i for i in input().split()]
 k = len(set(n))
 if k == 3:
  print(27)
 elif k == 2:
  print(8)
 elif k == 1:
  print(1)
 t = t - 1

for i in range(int(input())):
 a,n=map(int,input().split())
 a=set(str(a))
 if(len(a)==3):
  print(27)
 elif(len(a)==2):
  print(8)
 else:
  print(1)

# cook your dish here
for _ in range(int(input())):
 a,n=map(int,input().split())
 a=set(str(a))
 if(len(a)==3):
  print(27)
 elif(len(a)==2):
  print(8)
 else:
  print(1)

# cook your dish here
for i in range(int(input())):
 a = list(map(int, input().split()))
 l = list(map(int, str(a[0])))
 t = len(set(l))
 
 if t == 3:
  print("27")
 elif t == 2:
  print("8")
 else:
  print("1")


# cook your dish her
for _ in range(int(input())):
 s=input().split()
 print(len(set(s[0]))**3)

for _ in range(int(input())):
 s=input().split()
 print(len(set(s[0]))**3)

t=int(input())
while(t>0):
 t-=1
 nk=list(map(int,input().split()))
 n=int(nk[0])
 k=int(nk[1])
 arr=[0]*10
 while n>0:
  temp = n%10
  n = int(n/10)
  arr[temp] = 1
 count = 0;
 for i in range(10):
  if(arr[i]==1):
   count+=1
 print(count**3);

# cook your dish here
# cook your dish here
for _ in range(int(input())):
 s=input().split()
 x=len(set(s[0]))
 print(x*x*x)


for i in range(int(input())):
 a,b=map(int,input().split())
 a=set(str(a))
 print(len(a)**3)

for i in range(int(input())):
 a,b=map(int,input().split())
 a=set(str(a))
 print(len(a)**3)

# cook your dish here
for i in range(int(input())):
 a,b=map(int,input().split())
 a=set(str(a))
 print(len(a)**3)

# cook your dish here
try:
 t=int(input())
except:
 t=0
for i in range(t):
 X=list(map(int,input().split()))
 r=X[0]%10
 q=(X[0]%100-r)/10
 p=(X[0]-q*10-r)/100
 N=[0]*10
 N[int(p)]+=1
 N[int(q)]+=1
 N[int(r)]+=1
 ans=4-max(N)
 print(ans**3)

for t in range(int(input())):
 a, b = list(map(int, input().split()))
 a = set(str(a))
 l = (len(a) ** 3)
 print(l)


# cook your dish here
for _ in range(int(input())):
 inp = [int(x) for x in input().split()]
 K = inp[0]; N = inp[1];
 k1 = K%10; k2 = (K//10)%10; k3 = (K//100)
 if k1 == k2 == k3:
  print(1)
 elif k1 == k2 or k2 == k3 or k1 == k3:
  print(8)
 else:
  print(27)

for _ in range(int(input())):
 k, n = input().split()
 a = list(k)
 x= len(set(a))
 print(x ** 3)