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 MAXp = 100000;
int p, d;
int p10[8];
int dig[8];
bool ip[MAXp];
int num[8];
vector<int> v[6][10][6][MAXp / 100];
int ans = 0;
void init() {
  p10[0] = 1;
  for (int i = 1; i < 8; i++) p10[i] = p10[i - 1] * 10;
  ip[0] = ip[1] = 1;
  for (int i = 2; i < MAXp; i++)
    if (!ip[i]) {
      for (int d = (1), _n = (5); d <= _n; d++)
        for (int y = (0), _n = (min(d, 3)); y <= _n; y++)
          if (i / p10[d - 1] < 10)
            v[d][i / p10[d - 1]][y][i % p10[y]].push_back(i);
      if (i < 1000)
        for (long long j = i * i; j < MAXp; j += i) ip[j] = 1;
    }
}
void bt(int r) {
  if (r == 0) {
    ans++;
    return;
  }
  vector<int> &f = v[d][dig[r]][d - r - 1][num[r]];
  int z = int((f).size());
  int c = d - r - 1;
  for (int i = 0, _n = (z); i < _n; i++) {
    int x = f[i];
    for (int j = (1), _n = (r - 1); j <= _n; j++)
      num[j] += (x / p10[d - j - 1] % 10) * p10[c];
    bt(r - 1);
    for (int j = (1), _n = (r - 1); j <= _n; j++)
      num[j] -= (x / p10[d - j - 1] % 10) * p10[c];
  }
}
int main() {
  init();
  int ts;
  for (cin >> ts; ts--;) {
    cin >> p;
    int tmp = p;
    d = 0;
    while (tmp) dig[d++] = tmp % 10, tmp /= 10;
    reverse(dig, dig + d);
    ans = 0;
    bt(d - 1);
    cout << ans << endl;
  }
  {
    int _;
    cin >> _;
  }
}