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 flag[100000];
int p[100000], tot, a[10][10], tmp[10], ten[10], cnt;
vector<int> G[100000];
inline void dfs(int dep, int n) {
  int cc = 0;
  if (dep == n) {
    cnt++;
    return;
  }
  for (int i = dep - 1; i >= 0; i--) {
    cc += a[dep][dep - 1 - i] * ten[i];
  }
  int low, up;
  if (cc >= 1) {
    low = cc * ten[n - dep];
    up = cc * ten[n - dep] + (ten[n - dep] - 1);
  } else {
    low = 0;
    up = ten[n - dep] - 1;
  }
  for (int i = 0; i < (int)G[cc].size(); i++) {
    int cur = G[cc][i];
    if (cur < low) continue;
    if (cur > up) break;
    for (int j = dep; j < n; j++) a[dep][j] = a[j][dep] = 0;
    int now = n - 1;
    while (cur && now >= dep) {
      a[dep][now] = a[now][dep] = cur % 10;
      now--;
      cur /= 10;
    }
    dfs(dep + 1, n);
  }
}
int main() {
  for (int i = 2; i < 100000; i++) {
    if (!flag[i]) p[tot++] = i;
    for (int j = 0; j < tot && p[j] * i < 100000; j++) {
      flag[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = 0; i < tot; i++) {
    G[p[i] / 10].push_back(p[i]);
    G[p[i] / 100].push_back(p[i]);
    G[p[i] / 1000].push_back(p[i]);
    G[p[i] / 10000].push_back(p[i]);
  }
  for (int i = 0; i <= 10000; i++) {
    if ((int)G[i].size() == 0) continue;
    sort(G[i].begin(), G[i].end());
    vector<int>::iterator it = unique(G[i].begin(), G[i].end());
    G[i].erase(it, G[i].end());
  }
  ten[0] = 1;
  for (int i = 1; i < 10; i++) ten[i] = ten[i - 1] * 10;
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    int p;
    scanf("%d", &p);
    int n = 0;
    while (p) {
      tmp[n++] = p % 10;
      p /= 10;
    }
    for (int i = 0; i < n; i++)
      a[0][i] = tmp[n - 1 - i], a[i][0] = tmp[n - 1 - i];
    cnt = 0;
    dfs(1, n);
    printf("%d\n", cnt);
  }
  return 0;
}