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:60000000")
using namespace std;
template <class T>
T sqr(T x) {
  return x * x;
}
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9;
long long const inf64 = (long long)4e18;
const string name = "e";
const int NMAX = 100000;
int n, ans, p[6], prime[NMAX];
vector<vector<int> > nxt[6][6][NMAX];
int isprime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0) return 0;
  return 1;
}
void rec(int now) {
  if (now == n - 1) {
    ans += nxt[n][n - 1][p[n - 1]].size();
    return;
  }
  int tmp = p[now];
  for (int it = 0; it < (int)nxt[n][now][tmp].size(); it++) {
    int cnt = 0;
    for (int i = now; i < n; ++i)
      p[i] = 10 * p[i] + nxt[n][now][tmp][it][cnt++];
    rec(now + 1);
    for (int i = now; i < n; ++i) p[i] /= 10;
  }
}
void solve() {
  int now;
  cin >> now;
  int tmp = now;
  n = 0;
  while (now > 0) {
    p[n] = now % 10;
    now /= 10;
    n++;
  }
  reverse(p, p + n);
  p[0] = tmp;
  ans = 0;
  rec(1);
  cout << ans << endl;
}
int main() {
  for (int i = 0; i < (int)100000; i++)
    if (i > 1 && isprime(i)) {
      prime[i] = 1;
      int now = i, sz = 0;
      while (now > 0) now /= 10, sz++;
      now = i;
      vector<int> zn;
      int ok = 1;
      while (ok) {
        vector<int> buf = zn;
        if (now == 0) ok = 0;
        for (int j = 0; j < (int)5 - sz + 1; j++)
          if (now == 0 || j == 0) {
            for (int i = sz + j; i <= 5; ++i) {
              nxt[i][i - zn.size()][now].push_back(zn);
              reverse((nxt[i][i - zn.size()][now]
                          [nxt[i][i - zn.size()][now].size() - 1])
                          .begin(),
                      (nxt[i][i - zn.size()][now]
                          [nxt[i][i - zn.size()][now].size() - 1])
                          .end());
            }
            zn.push_back(0);
          }
        zn = buf;
        zn.push_back(now % 10);
        now /= 10;
      }
    } else
      prime[i] = 0;
  cerr << clock() << endl;
  int tst;
  cin >> tst;
  for (int i = 0; i < (int)tst; i++) solve();
  cerr << clock() << endl;
  return 0;
}