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>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
using namespace std;
double EPS = 1e-7;
int p[100001];
vector<int> P;
map<string, vector<string> > D[6];
;
map<string, vector<string> > d;
map<vector<string>, int> m;
int AA;
int f(vector<string>& s) {
  if (s.size() == 1) return D[AA][s[0]].size();
  if (m.find(s) != m.end()) return m[s];
  for (int i = 0; i < s.size(); i++) {
    if (D[AA][s[i]].size() == 0) return m[s] = 0;
  }
  string& S = s[0];
  int res = 0;
  vector<string> aa;
  for (int j = 1; j < s.size(); j++) {
    aa.push_back(s[j]);
    aa[j - 1] += 47;
  }
  int x = aa[0].size() - 1;
  vector<string>& A = D[AA][S];
  for (int i = 0; i < A.size(); i++) {
    for (int j = 1; j < s.size(); j++) {
      aa[j - 1][x] = A[i][x + j];
    }
    res += f(aa);
  }
  return m[s] = res;
}
void init(int x) {
  int n = 1;
  for (int i = 0; i < x; i++) {
    n *= 10;
  }
  d.clear();
  P.clear();
  for (int i = 2; i <= n; i++) {
    if (!p[i]) P.push_back(i);
  }
  for (int i = 0; i < P.size(); i++) {
    string s;
    int X = P[i];
    for (int j = 0; j < x; j++) {
      s += (char)(X % 10 + '0');
      X /= 10;
    }
    reverse(s.begin(), s.end());
    string s1;
    for (int j = 0; j < s.size(); j++) {
      s1 += s[j];
      d[s1].push_back(s);
    }
  }
}
int main() {
  int n = 100000;
  for (int i = 2; i * i <= n; i++) {
    if (p[i]) continue;
    for (int j = i * i; j <= n; j += i) {
      p[j] = 1;
    }
  }
  for (int i = 1; i <= 5; i++) {
    init(i);
    D[i] = d;
  }
  int tt;
  cin >> tt;
  for (; tt; tt--) {
    string s;
    cin >> s;
    vector<string> S;
    for (int i = 1; i < s.length(); i++) {
      S.push_back(string());
      S[i - 1] += s[i];
    }
    AA = s.length();
    int res = f(S);
    cout << res << endl;
  }
}