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:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
  return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
  return a * a;
}
const long double PI = 3.1415926535897932384626433832795;
const long double EPS = 1e-9;
const int INF = 1000 * 1000 * 1000;
string toStr(int n) {
  string res = "";
  while (n > 0) res.push_back(n % 10 + '0'), n /= 10;
  if (res.empty()) res.push_back('0');
  reverse((res).begin(), (res).end());
  return res;
}
const int N = 100 * 1000 + 13;
int deg[10];
int ans;
int cur[5];
int good[10];
int prime[N];
string pr;
int len;
void go(int x, int y) {
  if (x == len) {
    int res = 1;
    for (int i = 1; i <= int(len - 1); i++) {
      int curVal = 0;
      for (int j = 0; j < int(10); j++)
        if (prime[cur[i] + j * deg[len - 1 - i]]) curVal++;
      res *= curVal;
      if (res == 0) break;
    }
    ans += res;
    return;
  }
  if (y == len) return go(x + 1, x + 2);
  for (int i = 0; i < int(10); i++) {
    if (y == len - 1 && !good[i]) continue;
    int cur1 = cur[x], cur2 = cur[y];
    cur[x] += i * deg[len - 1 - y];
    cur[y] += i * deg[len - 1 - x];
    go(x, y + 1);
    cur[x] = cur1;
    cur[y] = cur2;
  }
}
int solve(int p) {
  ans = 0;
  cur[0] = p;
  pr = toStr(p);
  len = int((pr).size());
  for (int i = 1; i <= int(len - 1); i++) cur[i] = (pr[i] - '0') * deg[len - 1];
  go(1, 2);
  return ans;
}
int main() {
  deg[0] = 1;
  for (int i = 1; i <= int(9); i++) deg[i] = deg[i - 1] * 10;
  for (int i = 0; i < int(10); i++)
    if (i % 2 == 1 || i == 2) good[i] = true;
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i < N; i++)
    if (prime[i])
      for (int j = 2 * i; j < N; j += i) prime[j] = false;
  int testCount;
  cin >> testCount;
  for (int test = 0; test < int(testCount); test++) {
    int p;
    scanf("%d", &p);
    printf("%d\n", solve(p));
  }
  return 0;
}