Problem: You are given two positive integers a and b. There are two possible operations: 

  1. multiply one of the numbers by some prime p; 
  2. divide one of the numbers on its prime factor p. 



What is the minimum number of operations required to obtain two integers having the same number of divisors? You are given several such pairs, you need to find the answer for each of them.

Input

The first line contains a single integer t (1 ≤ t ≤ 10^5) — the number of pairs of integers for which you are to find the answer.

Each of the next t lines contain two integers a_i and b_i (1 ≤ a_i, b_i ≤ 10^6).

Output

Output t lines — the i-th of them should contain the answer for the pair a_i, b_i.

Example

Input

8
9 10
100 17
220 70
17 19
4 18
32 20
100 32
224 385


Output

1
3
1
0
1
0
1
1

Note

These are the numbers with equal number of divisors, which are optimal to obtain in the sample test case: 

  * (27, 10), 4 divisors 
  * (100, 1156), 9 divisors 
  * (220, 140), 12 divisors 
  * (17, 19), 2 divisors 
  * (12, 18), 6 divisors 
  * (50, 32), 6 divisors 
  * (224, 1925), 12 divisors 



Note that there can be several optimal pairs of numbers.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6000;
const int MAXD = 1100;
const int MAXK = 30;
const int MAXH = 1100000;
const int BASE = 233;
const int MOD = 1000003;
const int INF = 0X3F3F3F3F;
const int pri[MAXK] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
                       43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int n, t[MAXK];
int c[MAXN], f[MAXN];
int d[MAXN][MAXK];
int id[MAXH], dis[MAXN];
int val[MAXN][MAXD];
bool vis[MAXN];
vector<int> g[MAXN];
int get_factor(int n) {
  int m = 0;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      t[m] = 0;
      while (n % i == 0) t[m]++, n /= i;
      m++;
    }
  if (n > 1) t[m++] = 1;
  sort(t, t + m, greater<int>());
  int h = 0;
  for (int i = 0; i < m; i++) h = (1ll * h * BASE + t[i]) % MOD;
  return h;
}
void dfs(int k, int l, int s) {
  c[++n] = k;
  f[n] = 1;
  int h = 0;
  for (int i = 0; i < k; i++) {
    d[n][i] = t[i];
    h = (1ll * h * BASE + t[i]) % MOD;
    f[n] *= (t[i] + 1);
  }
  id[h] = n;
  for (int i = min(l, s); i >= 1; i--) t[k] = i, dfs(k + 1, i, s - i);
}
int main() {
  dfs(0, 22, 22);
  for (int i = 1; i <= n; i++) {
    int s = 0;
    for (int j = 0; j < c[i]; j++) s += d[i][j];
    if (s < 22)
      for (int j = 0; j <= c[i]; j++) {
        for (int k = 0; k <= c[i]; k++) t[k] = d[i][k];
        t[j]++;
        sort(t, t + c[i] + 1, greater<int>());
        int h = 0;
        for (int j = 0; j <= c[i] && t[j]; j++)
          h = (1ll * h * BASE + t[j]) % MOD;
        g[i].push_back(id[h]);
      }
    if (s > 0)
      for (int j = 0; j < c[i]; j++) {
        for (int k = 0; k < c[i]; k++) t[k] = d[i][k];
        t[j]--;
        sort(t, t + c[i], greater<int>());
        int h = 0;
        for (int j = 0; j < c[i] && t[j]; j++)
          h = (1ll * h * BASE + t[j]) % MOD;
        g[i].push_back(id[h]);
      }
  }
  memset(val, INF, sizeof val);
  for (int i = 1; i <= n; i++) {
    bool flag = 1;
    for (int j = 0, r = 1; j < c[i]; j++) {
      for (int k = 1; k <= d[i][j]; k++) r *= pri[j];
      if (r > 1E6) {
        flag = 0;
        break;
      }
    }
    if (!flag) continue;
    queue<int> que;
    memset(vis, 0, sizeof vis);
    dis[i] = 0, que.push(i), vis[i] = 1;
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
        if (!vis[v]) dis[v] = dis[u] + 1, que.push(v), vis[v] = 1;
      }
    }
    for (int j = 1; j <= n; j++)
      if (f[j] <= 1E3) val[i][f[j]] = min(val[i][f[j]], dis[j]);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int u = id[get_factor(a)], v = id[get_factor(b)];
    int ans = INF;
    for (int i = 1; i <= 1E3; i++) ans = min(ans, val[u][i] + val[v][i]);
    printf("%d\n", ans);
  }
  return 0;
}