Problem: Polycarpus has t safes. The password for each safe is a square matrix consisting of decimal digits '0' ... '9' (the sizes of passwords to the safes may vary). Alas, Polycarpus has forgotten all passwords, so now he has to restore them.

Polycarpus enjoys prime numbers, so when he chose the matrix passwords, he wrote a prime number in each row of each matrix. To his surprise, he found that all the matrices turned out to be symmetrical (that is, they remain the same after transposition). Now, years later, Polycarp was irritated to find out that he remembers only the prime numbers pi, written in the first lines of the password matrices.

For each safe find the number of matrices which can be passwords to it.

The number of digits in pi determines the number of rows and columns of the i-th matrix. One prime number can occur in several rows of the password matrix or in several matrices. The prime numbers that are written not in the first row of the matrix may have leading zeros.

Input

The first line of the input contains an integer t (1 ≤ t ≤ 30) — the number of safes. Next t lines contain integers pi (10 ≤ pi ≤ 99999), pi is a prime number written in the first row of the password matrix for the i-th safe. All pi's are written without leading zeros.

Output

Print t numbers, the i-th of them should be the number of matrices that can be a password to the i-th safe. Print the numbers on separate lines.

Examples

Input

4
11
239
401
9001


Output

4
28
61
2834

Note

Here is a possible password matrix for the second safe: 
    
    
      
    239  
    307  
    977  
    

Here is a possible password matrix for the fourth safe: 
    
    
      
    9001  
    0002  
    0002  
    1223   
    

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 10;
int MAXL = 100 * 1000;
const int MAXD = 1000 * 1000;
bool isprim[MAXN];
int t;
string N;
char ch[7][7];
int Ten[7];
int l, k, num;
int Get[7];
char tostr[MAXD][7];
long long sum;
int CanNum(int r) {
  int ans = 0;
  for (__typeof(10) i = (0); i < (10); ++i) {
    int cur = Get[r] + Ten[k - r - 1] * i;
    ans += isprim[cur];
  }
  return ans;
}
void Proces(int s) {
  int t = k - 1, tot = 0;
  for (__typeof(t) i = (1); i < (t); ++i) {
    for (__typeof(k) j = (i + 1); j < (k); ++j) {
      ch[i][j] = ch[j][i] = tostr[s][tot++];
    }
    if (ch[i][k - 1] == '0') return;
  }
  for (__typeof(k) i = (1); i < (k); ++i) {
    Get[i] = 0;
    for (__typeof(k) j = (0); j < (k); ++j) {
      Get[i] = Get[i] * 10;
      if (i != j) Get[i] += (ch[i][j] - '0');
    }
  }
  int mul = 1;
  for (__typeof(k) i = (1); i < (k); ++i) mul *= CanNum(i);
  sum += mul;
}
int main() {
  for (__typeof(MAXL) i = (2); i < (MAXL); ++i) isprim[i] = true;
  for (__typeof(MAXL) i = (2); i < (MAXL); ++i) {
    if (isprim[i]) {
      for (long long j = i; i * j < MAXL; ++j) isprim[i * j] = false;
    }
  }
  for (__typeof((int)MAXD) i = (0); i < ((int)MAXD); ++i) {
    int a = i;
    for (__typeof(6) j = (0); j < (6); ++j) {
      tostr[i][j] = char('0' + a % 10);
      a /= 10;
    }
  }
  Ten[0] = 1;
  for (__typeof(7) i = (1); i < (7); ++i) Ten[i] = Ten[i - 1] * 10;
  cin >> t;
  while (t--) {
    cin >> N;
    k = ((int)(N).size());
    l = (k - 2) * (k - 1) / 2;
    num = Ten[l];
    for (__typeof(k) i = (0); i < (k); ++i) ch[0][i] = ch[i][0] = N[i];
    sum = 0;
    for (__typeof(num) lv1 = (0); lv1 < (num); ++lv1) Proces(lv1);
    cout << sum << endl;
  }
  return 0;
}