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:100000000")
using namespace std;
template <class T>
T inline sqr(T x) {
  return x * x;
}
template <class T>
string str(T i) {
  stringstream ss;
  ss << i;
  return ss.str();
}
int toint(string a) {
  istringstream is(a);
  int p;
  is >> p;
  return p;
}
long long toll(string a) {
  istringstream is(a);
  long long p;
  is >> p;
  return p;
}
const long double pi = 3.1415926535897932384626433832795, eps = 1e-8;
const int maxnum = 100500, maxdig = 7;
int a[10][10];
bool d[maxnum][10];
vector<int> b[maxnum][maxdig];
int st[10];
bool pr[maxnum];
vector<int> g;
inline int ans(int x) {
  int cx = x, dig = 0, i;
  while (cx > 0) {
    a[0][dig] = cx % 10;
    cx /= 10;
    dig++;
  };
  for (i = 0; i < int((dig >> 1)); i++) swap(a[0][i], a[0][dig - 1 - i]);
  int res = 0, a0 = a[0][0], a1 = a[0][1], a2 = a[0][2], a3 = a[0][3],
      a4 = a[0][4];
  if (dig == 2) {
    for (i = 0; i < int(10); i++)
      if (pr[10 * a1 + i]) res++;
    return res;
  }
  int i1, i2, i3, i4, i5, i6;
  if (dig == 3) {
    for (i1 = 0; i1 < int(10); i1++)
      for (i2 = 0; i2 < int(10); i2++)
        for (i3 = 0; i3 < int(10); i3++)
          if (pr[a1 * 100 + i1 * 10 + i2] && pr[a2 * 100 + i2 * 10 + i3]) res++;
    return res;
  }
  if (dig == 4) {
    for (i1 = 0; i1 < int(10); i1++)
      for (i2 = 0; i2 < int(10); i2++)
        for (i3 = 0; i3 < int(10); i3++)
          if (pr[a1 * 1000 + i1 * 100 + i2 * 10 + i3]) {
            for (i4 = 0; i4 < int(10); i4++)
              for (i5 = 0; i5 < int(10); i5++)
                if (pr[a2 * 1000 + i2 * 100 + i4 * 10 + i5]) {
                  for (i6 = 0; i6 < int(10); i6++)
                    if (pr[a3 * 1000 + i3 * 100 + i5 * 10 + i6]) res++;
                }
          }
    return res;
  }
  int z, j, y, i7, i8, i9, i10, k, l, e;
  if (dig == 5) {
    for (i = 0; i < int(b[a1][0].size()); i++) {
      z = b[a1][0][i];
      i1 = z / 1000;
      z %= 1000;
      i2 = z / 100;
      z %= 100;
      i3 = z / 10;
      z %= 10;
      i4 = z;
      for (j = 0; j < int(b[a2 * 10 + i2][1].size()); j++) {
        y = b[a2 * 10 + i2][1][j];
        i5 = y / 100;
        y %= 100;
        i6 = y / 10;
        y %= 10;
        i7 = y;
        for (k = 0; k < int(b[a3 * 100 + i3 * 10 + i6][2].size()); k++) {
          e = b[a3 * 100 + i3 * 10 + i6][2][k];
          i8 = e / 10;
          i9 = e % 10;
          res += b[a4 * 1000 + i4 * 100 + i7 * 10 + i9][3].size();
        }
      }
    }
    return res;
  }
};
inline bool P(int x) {
  int i;
  for (i = 2; i * i <= x; i++)
    if (x % i == 0) {
      return false;
    }
  return true;
}
int cx, dig = 0;
vector<int> w;
int i;
int y = 0;
void proc(int x) {
  cx = x, dig = 0;
  w.resize(0);
  while (cx > 0) {
    w.push_back(cx % 10);
    dig++;
    cx /= 10;
  }
  for (i = dig; i < 5; i++) w.push_back(0);
  dig = 5;
  for (i = 0; i < int(dig / 2); i++) swap(w[i], w[dig - i - 1]);
  y = 0;
  for (i = 0; i < int(dig); i++) {
    y = 10 * y + w[i];
    b[y][i].push_back(x - y * st[dig - i - 1]);
  }
}
int main() {
  int t, i, x, res;
  st[0] = 1;
  for (i = 1; i < 8; i++) st[i] = st[i - 1] * 10;
  for (i = 2; i < 100000; i++)
    if (P(i)) {
      pr[i] = true;
      proc(i);
    }
  cin >> t;
  for (i = 0; i < int(t); i++) {
    cin >> x;
    if (!pr[x])
      res = 0;
    else
      res = ans(x);
    cout << res << endl;
  }
  return 0;
}