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 = 1e5 + 5;
struct state {
  int level;
  int num[10];
  state() { num[0] = num[1] = num[2] = num[3] = num[4] = num[5] = 0; }
  state(int level, vector<int> v) {
    num[0] = num[1] = num[2] = num[3] = num[4] = num[5] = 0;
    this->level = level;
    for (int i = 0; i < v.size(); i++) {
      this->num[i] = v[i];
    }
  }
};
long long memo1[11][11][11][11];
long long memo2[101][101][101];
long long memo3[1001][1001];
long long memo4[10001];
vector<int> number2Vector(int x) {
  vector<int> output;
  while (x != 0) {
    output.push_back(x % 10);
    x /= 10;
  }
  reverse(output.begin(), output.end());
  return output;
}
int digCnt(int x) {
  int cnt = 0;
  while (x != 0) {
    x /= 10;
    cnt++;
  }
  return cnt;
}
bool notPrime[MAXN];
vector<int> prefix2Primes[MAXN];
void Init() {
  memset(memo1, -1, sizeof(memo1));
  memset(memo2, -1, sizeof(memo2));
  memset(memo3, -1, sizeof(memo3));
  memset(memo4, -1, sizeof(memo4));
  for (int i = 2; i * i < MAXN; i++) {
    if (notPrime[i] == true) continue;
    for (int j = i * i; j < MAXN; j += i) {
      notPrime[j] = true;
    }
  }
  for (int i = 2; i < MAXN; i++) {
    if (notPrime[i] == true) continue;
    int prefix = 0;
    vector<int> v = number2Vector(i);
    prefix2Primes[i].push_back(i);
    for (int d : v) {
      prefix2Primes[prefix].push_back(i);
      prefix = prefix * 10 + d;
    }
  }
}
long long calcState(state st) {
  if (st.level == 5) {
    return 1;
  }
  if (st.level == 1) {
    if (memo1[st.num[0]][st.num[1]][st.num[2]][st.num[3]] != -1) {
      return memo1[st.num[0]][st.num[1]][st.num[2]][st.num[3]];
    }
  }
  if (st.level == 2) {
    if (memo2[st.num[0]][st.num[1]][st.num[2]] != -1) {
      return memo2[st.num[0]][st.num[1]][st.num[2]];
    }
  }
  if (st.level == 3) {
    if (memo3[st.num[0]][st.num[1]] != -1) {
      return memo3[st.num[0]][st.num[1]];
    }
  }
  if (st.level == 4) {
    if (memo4[st.num[0]] != -1) {
      return memo4[st.num[0]];
    }
  }
  long long answer = 0;
  for (int x : prefix2Primes[st.num[0]]) {
    if (st.num[0] != 0 && digCnt(x) != 5 - (st.level - digCnt(st.num[0])))
      continue;
    if (st.num[0] == 0 && digCnt(x) > 5 - st.level) continue;
    vector<int> number = number2Vector(x);
    while (number.size() < 5) {
      number.insert(number.begin(), 0);
    }
    vector<int> prefixes;
    for (int j = st.level + 1; j < 5; j++) {
      prefixes.push_back(st.num[j - st.level] * 10 + number[j]);
    }
    answer += calcState(state(st.level + 1, prefixes));
  }
  if (st.level == 1) {
    memo1[st.num[0]][st.num[1]][st.num[2]][st.num[3]] = answer;
  }
  if (st.level == 2) {
    memo2[st.num[0]][st.num[1]][st.num[2]] = answer;
  }
  if (st.level == 3) {
    return memo3[st.num[0]][st.num[1]] = answer;
  }
  if (st.level == 4) {
    memo4[st.num[0]] = answer;
  }
  return answer;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  Init();
  int T;
  cin >> T;
  while (T--) {
    int x;
    cin >> x;
    vector<int> v = number2Vector(x);
    v.erase(v.begin());
    cout << calcState(state(5 - v.size(), v)) << '\n';
  }
}