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 = 100000;
const int MAX_NUM_LEN = 5;
vector<int> primes;
int mem[N][MAX_NUM_LEN + 1][MAX_NUM_LEN + 1];
int pow_ten[MAX_NUM_LEN + 3];
int num_size(int num) {
  int res = 0;
  while (num > 0) {
    num /= 10;
    res++;
  }
  return res;
}
int delete_number(int num, int pos, int num_sz) {
  return (num % pow_ten[num_sz - pos - 1]) +
         (num / pow_ten[num_sz - pos]) * pow_ten[num_sz - pos - 1];
}
int get_part(int num, int till_pos, int num_sz) {
  return (num / pow_ten[num_sz - till_pos - 1]);
}
int get_number(int num, int pos, int num_sz) {
  int a = (num % pow_ten[num_sz - pos]) / pow_ten[num_sz - pos - 1];
  return a;
}
void gen_primes() {
  vector<bool> is_prime(N + 1, true);
  for (long long i = 2; i <= N; ++i) {
    if (is_prime[i]) {
      for (long long j = i * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      primes.push_back(i);
    }
  }
}
void do_preprocessing() {
  pow_ten[0] = 1;
  for (int i = 1; i <= MAX_NUM_LEN + 2; ++i) {
    pow_ten[i] = pow_ten[i - 1] * 10;
  }
  for (int j = 0; j < primes.size(); ++j) {
    for (int len = 2; len <= MAX_NUM_LEN; ++len) {
      for (int i = 1; i < len; ++i) {
        int sz = num_size(primes[j]);
        if (sz > len) break;
        if (i < len - sz) {
          ++mem[primes[j]][i][len];
        } else {
          ++mem[delete_number(primes[j], i - (len - sz), sz)][i][len];
        }
      }
    }
  }
}
vector<int> cur_state;
int sz;
int sum = 0;
int make_number(int i, int second) {
  int res = get_number(cur_state[0], i, sz) * pow_ten[sz - 2];
  for (int j = 1; j < i; ++j) {
    res += pow_ten[sz - j - 2] * get_number(cur_state[j], i - 1, sz - 1);
  }
  if (second >= 0) {
    return res + second;
  } else {
    return res;
  }
}
void do_brut_force(int i) {
  if (i == sz) {
    int add = 1;
    for (int j = 1; j < sz; ++j) {
      add *= mem[cur_state[j]][j][sz];
    }
    sum += add;
  } else {
    if (sz - i - 1 == 0) {
      cur_state[i] = make_number(i, -1);
      if (mem[cur_state[i]][i][sz] == 0) return;
      do_brut_force(i + 1);
    } else {
      for (int num = 0; num < pow_ten[sz - i - 1]; ++num) {
        cur_state[i] = make_number(i, num);
        if (mem[cur_state[i]][i][sz] == 0) continue;
        do_brut_force(i + 1);
      }
    }
  }
}
int main() {
  gen_primes();
  do_preprocessing();
  int T;
  cin >> T;
  for (int t = 0; t < T; ++t) {
    int p;
    cin >> p;
    sz = num_size(p);
    cur_state.resize(sz);
    cur_state[0] = p;
    sum = 0;
    do_brut_force(1);
    cout << sum << endl;
  }
}