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;
bool np[100005];
vector<int> prime;
int cnt[161060];
void sieve(int n) {
  for (int i = (2); i <= (n); i++) {
    if (np[i]) continue;
    prime.push_back(i);
    int t = i;
    int tmp[5];
    for (int j = (0); j <= (4); j++) tmp[j] = t % 10, t /= 10;
    for (int j = (0); j <= (4); j++) {
      int t = 0;
      for (int k = (4); k >= (0); k--) {
        t *= 11;
        if (j == k)
          t += 10;
        else
          t += tmp[k];
      }
      cnt[t]++;
    }
    for (long long j = 1LL * i * i; j <= n; j += i) np[j] = 1;
  }
}
int s;
int fr[6];
long long memo[6][10005];
long long dp(int i, int st) {
  if (memo[i][st] != -1) return memo[i][st];
  int tmp[6];
  for (int j = (0); j <= (5); j++) tmp[j] = st % 10, st /= 10;
  long long res = 0;
  if (s == 2) {
    res = (res + cnt[fr[1] * 11 + 10]) % 1000000007;
  } else if (s == 3) {
    if (i == 2) {
      for (int j = (0); j <= (9); j++) {
        long long c = cnt[fr[1] * 121 + 10 * 11 + j];
        if (!c) continue;
        res = (res + c * dp(i + 1, j)) % 1000000007;
      }
    } else if (i == 3) {
      res = (res + cnt[fr[2] * 121 + tmp[0] * 11 + 10]) % 1000000007;
    }
  } else if (s == 4) {
    if (i == 2) {
      for (int j = (0); j <= (9); j++)
        for (int k = (0); k <= (9); k++) {
          long long c = cnt[fr[1] * 1331 + 10 * 121 + j * 11 + k];
          if (!c) continue;
          res = (res + c * dp(i + 1, k * 10 + j)) % 1000000007;
        }
    } else if (i == 3) {
      for (int j = (0); j <= (9); j++) {
        long long c = cnt[fr[2] * 1331 + tmp[0] * 121 + 10 * 11 + j];
        if (!c) continue;
        res = (res + c * dp(i + 1, j * 10 + tmp[1])) % 1000000007;
      }
    } else if (i == 4) {
      res = (res + cnt[fr[3] * 1331 + tmp[0] * 121 + tmp[1] * 11 + 10]) %
            1000000007;
    }
  } else if (s == 5) {
    if (i == 2) {
      for (int j = (0); j <= (9); j++)
        for (int k = (0); k <= (9); k++)
          for (int l = (0); l <= (9); l++) {
            long long c = cnt[fr[1] * 14641 + 10 * 1331 + j * 121 + k * 11 + l];
            if (!c) continue;
            res = (res + c * dp(i + 1, l * 100 + k * 10 + j)) % 1000000007;
          }
    } else if (i == 3) {
      for (int j = (0); j <= (9); j++)
        for (int k = (0); k <= (9); k++) {
          long long c =
              cnt[fr[2] * 14641 + tmp[0] * 1331 + 10 * 121 + j * 11 + k];
          if (!c) continue;
          res =
              (res + c * dp(i + 1, k * 1000 + tmp[2] * 100 + j * 10 + tmp[1])) %
              1000000007;
        }
    } else if (i == 4) {
      for (int j = (0); j <= (9); j++) {
        long long c =
            cnt[fr[3] * 14641 + tmp[0] * 1331 + tmp[1] * 121 + 10 * 11 + j];
        if (!c) continue;
        res =
            (res + c * dp(i + 1, j * 100 + tmp[3] * 10 + tmp[2])) % 1000000007;
      }
    } else if (i == 5) {
      res = (res + cnt[fr[4] * 14641 + tmp[0] * 1331 + tmp[1] * 121 +
                       tmp[2] * 11 + 10]) %
            1000000007;
    }
  }
  return memo[i][st] = res;
}
int main() {
  sieve(100000);
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = (1); i <= (t); i++) {
    string S;
    cin >> S;
    s = S.length();
    for (int j = (0); j <= (s - 1); j++) fr[j] = S[j] - '0';
    memset(memo, -1, sizeof(memo));
    printf("%lld\n", dp(2, 0));
  }
  return 0;
}