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 pp[6] = {0, 1, 10, 100, 1000, 10000};
bool pri[100000];
int psum[100000];
int x[6][6], s[6];
int ans, sum, t;
bool is_prime(int x) {
  for (int i = 2; i <= (int)(sqrt(x) + 1e-8); i++)
    if (x % i == 0) return 0;
  return 1;
}
void prep() {
  memset(pri, 0, sizeof(pri));
  memset(psum, 0, sizeof(psum));
  for (int i = 2; i <= 99999; i++)
    if (is_prime(i)) {
      pri[i] = true;
      psum[i - (i / 10 % 10) * 10]++;
    }
}
void dfs(int tx, int ty) {
  if (tx == sum) {
    ans++;
    return;
  }
  if (tx == sum - 1 && ty == 2) {
    ans += psum[s[tx]];
    return;
  }
  int tt = 0, ttt = 0;
  for (int i = 0; i <= 9; i++) {
    x[tx][ty] = i;
    x[sum - ty + 1][sum - tx + 1] = i;
    s[tx] += ttt;
    if (tx + ty != sum + 1) s[sum - ty + 1] += tt;
    if (ty == 2) {
      if (pri[s[tx]]) dfs(tx + 1, sum - tx);
    } else
      dfs(tx, ty - 1);
    s[tx] -= ttt;
    if (tx + ty != sum + 1) s[sum - ty + 1] -= tt;
    tt += pp[sum - tx + 1];
    ttt += pp[ty];
  }
}
void Dfs(int tx) {
  const int num[7] = {0, 1, 3, 5, 7, 9, 2};
  for (int i = 1; i <= 6; i++) {
    if (i == 6 && x[tx][sum] != 0) return;
    x[tx][1] = num[i];
    x[sum][sum - tx + 1] = num[i];
    s[tx] += num[i] * pp[1];
    if (tx == sum) {
      if (pri[s[tx]]) dfs(2, sum - 1);
    } else {
      s[sum] += num[i] * pp[sum - tx + 1];
      Dfs(tx + 1);
      s[sum] -= num[i] * pp[sum - tx + 1];
    }
    s[tx] -= num[i] * pp[1];
  }
}
void solve() {
  int p;
  cin >> p;
  sum = 0;
  while (p > 0) {
    x[1][++sum] = p % 10;
    p /= 10;
  }
  for (int i = 2; i <= sum; i++) x[i][sum] = x[1][sum - i + 1];
  ans = 0;
  for (int i = 2; i <= sum; i++) s[i] = x[i][sum] * pp[sum];
  Dfs(2);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> t;
  prep();
  for (int i = 1; i <= t; i++) solve();
  return 0;
}