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 N = 1e5 + 7;
int T, n, tot, bit[10], a[10][10], f2[10][10][10][10], f3[10][10][10][10],
    f4[10][10][10][10], f5[10][10][10][10];
bool isp[N];
long long ans;
void sieve() {
  memset(isp, 1, sizeof(isp));
  isp[0] = 0;
  isp[1] = 0;
  for (int i = int(2); i <= int(N - 1); ++i) {
    for (int j = i + i; j < N; j += i) isp[j] = 0;
  }
}
void dfs(int x, int y) {
  if (x > tot) {
    int flag = 1;
    for (int i = int(2); i <= int(tot); ++i) {
      int num = 0;
      for (int j = int(1); j <= int(tot); ++j) num = num * 10 + a[i][j];
      if (isp[num] == 0) {
        flag = 0;
        break;
      }
    }
    ans += flag;
    return;
  }
  int xx = x, yy = y + 1;
  if (yy > tot) xx = yy = x + 1;
  for (int i = int(0); i <= int(9); ++i) {
    a[x][y] = a[y][x] = i;
    dfs(xx, yy);
  }
}
void dfs2(int x, int y) {
  if (x >= tot) {
    long long ret = 1;
    ret = f2[a[2][1]][a[2][3]][a[2][4]][a[2][5]];
    ret *= f3[a[3][1]][a[3][2]][a[3][4]][a[3][5]];
    ret *= f4[a[4][1]][a[4][2]][a[4][3]][a[4][5]];
    ret *= f5[a[5][1]][a[5][2]][a[5][3]][a[5][4]];
    ans += ret;
    return;
  }
  int xx = x, yy = y + 1;
  if (yy > tot) {
    xx = x + 1;
    yy = xx + 1;
  }
  if (y != 5)
    for (int i = int(0); i <= int(9); ++i) {
      a[x][y] = a[y][x] = i;
      dfs2(xx, yy);
    }
  else {
    a[x][y] = a[y][x] = 2;
    dfs2(xx, yy);
    for (int i = 1; i <= 9; i += 2) {
      a[x][y] = a[y][x] = i;
      dfs2(xx, yy);
    }
  }
}
int main() {
  sieve();
  for (int p = int(2); p <= int(99999); ++p)
    if (isp[p]) {
      int t1 = p / 10000;
      int t2 = (p / 1000) % 10;
      int t3 = (p / 100) % 10;
      int t4 = (p / 10) % 10;
      int t5 = p % 10;
      f2[t1][t3][t4][t5]++;
      f3[t1][t2][t4][t5]++;
      f4[t1][t2][t3][t5]++;
      f5[t1][t2][t3][t4]++;
    }
  cin >> T;
  while (T--) {
    cin >> n;
    tot = 0;
    ans = 0;
    while (n) {
      bit[++tot] = n % 10;
      n /= 10;
    }
    for (int i = int(1); i <= int(tot); ++i)
      for (int j = int(1); j <= int(tot); ++j) a[i][j] = -1;
    for (int i = int(1); i <= int(tot); ++i)
      a[1][i] = a[i][1] = bit[tot + 1 - i];
    if (tot <= 4)
      dfs(2, 2);
    else
      dfs2(2, 3);
    cout << ans << endl;
  }
}