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 = 1e6 + 5;
const int MAX = 1e6;
const int maxm = 2000;
vector<vector<int>> g;
vector<int> ed[maxm], f[maxn];
int pv[maxm], pv2[maxn], pri[11] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31},
                         tot = 0;
long long pm[maxm];
long long pw[11][50];
int dis[maxm][maxm * 2];
map<long long, int> mp;
int pvmax = 0, vis[maxn];
void dfs(int cur, long long mul, int val, int limt, vector<int>& now) {
  pv[(int)g.size()] = val;
  pvmax = max(pvmax, val);
  mp[mul] = (int)g.size();
  pm[(int)g.size()] = mul;
  g.push_back(now);
  long long x = pri[cur];
  for (int i = 1; i <= limt; ++i) {
    if (mul * pw[cur][i] >= MAX * 10000ll) break;
    now.push_back(i);
    dfs(cur + 1, mul * pw[cur][i], val * (i + 1), i, now);
    now.pop_back();
  }
}
int d[maxm];
void bfs(int s) {
  queue<int> q;
  q.push(s);
  memset(d, 0, sizeof(int) * (tot + 2));
  d[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : ed[u]) {
      if (!d[v]) {
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
  memset(dis[s], 0x3f, sizeof(dis[s]));
  for (int i = 1; i <= tot; ++i) dis[s][pv[i]] = min(dis[s][pv[i]], d[i] - 1);
}
int main() {
  for (int i = 0; i < 11; ++i) {
    int j = 1;
    pw[i][0] = 1;
    while (pw[i][j - 1] * pri[i] <= 1e15) pw[i][j] = pw[i][j - 1] * pri[i], j++;
  }
  vector<int> now;
  g.push_back(now);
  dfs(0, 1, 1, 22, now);
  for (int i = 2; i < maxn; ++i) {
    if (!vis[i]) {
      for (int j = i; j < maxn; j += i) {
        int u = j, ct = 0;
        while (u % i == 0) {
          u /= i;
          ct++;
        }
        f[j].push_back(ct);
        vis[j] = 1;
      }
    }
  }
  for (int i = 1; i < maxn; ++i) {
    sort(f[i].begin(), f[i].end(), greater<int>());
    long long mul = 1;
    for (int j = 0; j < f[i].size(); ++j) {
      mul *= pw[j][f[i][j]];
    }
    pv2[i] = mp[mul];
    f[i].clear();
  }
  for (int i = 1; i < g.size(); ++i) {
    long long x = pm[i];
    for (int j = 0; j < g[i].size(); ++j) {
      if (j == (int)g[i].size() || g[i][j] != g[i][j + 1]) {
        x /= pri[j];
        if (mp.count(x)) {
          ed[i].push_back(mp[x]);
          ed[mp[x]].push_back(i);
        }
        x *= pri[j];
      }
      if (!j || g[i][j] != g[i][j - 1]) {
        x *= pri[j];
        if (mp.count(x)) {
          ed[i].push_back(mp[x]);
          ed[mp[x]].push_back(i);
        }
        x /= pri[j];
      }
    }
    int sz = g[i].size();
    x *= pri[sz];
    if (mp.count(x)) {
      ed[i].push_back(mp[x]);
      ed[mp[x]].push_back(i);
    }
  }
  tot = (int)g.size() - 1;
  for (int i = 1; i <= tot; ++i) bfs(i);
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b;
    scanf("%d%d", &a, &b);
    a = pv2[a], b = pv2[b];
    int ans = 1e5, zh = 0;
    for (int i = 1; i <= pvmax; ++i) {
      if (ans > dis[a][i] + dis[b][i]) zh = i;
      ans = min(ans, dis[a][i] + dis[b][i]);
    }
    printf("%d\n", ans);
  }
}