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:16000000")
using namespace std;
const double pi = acos(-1.0);
bool iscomp[100000];
int pr[100000], prc;
void getPrimes() {
  memset(iscomp, 0, sizeof iscomp);
  ;
  prc = 0;
  for (int i = 2; i < 100000; i++)
    if (!iscomp[i]) {
      pr[prc++] = i;
      if (i <= 100000 / i)
        for (int j = i * i; j < 100000; j += i) iscomp[j] = true;
    }
}
struct Node {
  Node* a[10];
  vector<int> b[6];
  Node() {
    memset(a, 0, sizeof a);
    ;
  }
} root;
const int pw10[6] = {1, 10, 100, 1000, 10000, 100000};
void add(int x, int len) {
  Node* v = &root;
  while (1) {
    v->b[len].push_back(x);
    if (len == 0) break;
    int d = (x / pw10[len - 1]) % 10;
    if (v->a[d] == 0) v->a[d] = new Node();
    v = v->a[d];
    --len;
  }
}
int n;
int a[5][5];
long long res;
void rec(int s, Node** arr) {
  if (s == n) {
    ++res;
    return;
  }
  Node* v = arr[s];
  for (int k = 0, _n = ((int)(v->b[n - s]).size()); k < _n; k++) {
    Node* nw[5];
    bool bad = false;
    for (int x = v->b[n - s][k], j = n - 1; j >= s; j--, x /= 10) {
      a[j][s] = a[s][j] = x % 10;
      nw[j] = arr[j]->a[a[j][s]];
      if (nw[j] == 0 || nw[j]->b[n - s - 1].empty()) {
        bad = true;
        break;
      }
    }
    if (!bad) rec(s + 1, nw);
  }
}
int main() {
  getPrimes();
  for (int i = 0, _n = (prc); i < _n; i++) {
    int len = 0;
    for (int x = pr[i]; x; x /= 10) ++len;
    for (int j = len; j <= 5; j++) add(pr[i], j);
  }
  int tests;
  scanf("%d", &tests);
  for (int test = 1; test <= tests; test++) {
    int fst;
    scanf("%d", &fst);
    char buf[100];
    sprintf(buf, "%d", fst);
    n = strlen(buf);
    res = 0;
    Node* st[5];
    for (int i = 0, _n = (n); i < _n; i++) {
      a[0][i] = a[i][0] = buf[i] - '0';
      st[i] = root.a[a[i][0]];
    }
    rec(1, st);
    cout << res << endl;
  }
  return 0;
}