Problem: Darshak (Dark) was learning about numerals in words and he came across representation of "6743294" as shown below
.tg  {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;}

Ten Lakhs
Lakhs
Ten-Thousands
Thousands
Hundreds
Tens
Units
6
7
4
3
2
9
4
This can be extended to very high numbers like crores, ten crores and so on...

He learned two concepts.

1) Face Value:

The Face value of a digit in a numeral is its own value, at whatever place it may be.
eg: Face Value of 6 is 6 (as per above example) let say it is stored in 'f'

2) Place Value:

In a given numeral, 

Place value of unit digit = (unit digit * 1)

Place value of tens digit = (tens digit *10)

and so on,...

eg: place value of '4' at unit place is  4 * 1 = 4.

As always Dark is eager and wants you to find the place value of given digit and count the number of zero's present in it say let it be 'p' 

But, if the value of p comes out to be even number then we need to print the fth prime number or if it comes out to be odd then print the pth prime number. 

Note: Prime numbers start from 2.

Input:

First line contains t number of test case. Each next line contains one numeral say 'n' , 'm' the digit whose place value is to be obtained and 'x' position of the digit from units place towards the higher places.

Note: 
In an example, "6343"  if x=2 then it represents the "thousandth place" and if x=1 then "units place".we have considered digit as 3

Output:

Print the prime number as explained above.

Constraints:

1 ≤ t ≤ 1000
0 ≤ m ≤ 9 
1 ≤ x ≤ 100
1 ≤ n ≤ 10^101

Note:

1) Face value of zero is zero therefore the fth prime number i.e 0th prime number can be considered as 1.

2) Prime number starts from 2.

3)  No leading zeroes in the numeral.

Author : Darshak Mehta

SAMPLE INPUT
3
1005 0 2
7347 3 1
7777 7 4

SAMPLE OUTPUT
1
5
5

Solution (in PYTHON):

Solution:
T=input()
L=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607]
while(T):
	T-=1
	n,m,x=raw_input().split()
	x=int(x)
	count=0
	l=n[::-1]
	j=0
	for i in l:
		if(i==m):
			count+=1
			if(count==x):
				break
		j+=1
	if(j&1==0):
		if(m=='0'):
			print "1"
		else:
			print L[int(m)-1]
	else:
		print L[j-1]