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 N = 1000000 + 10;
const int B = 25;
bool cmp(int x, int y) { return x > y; }
int prime[N], d[N], vis[N], flag[N];
void init() {
  for (int i = 2; i < N; i++) {
    if (vis[i] == 0) {
      prime[++prime[0]] = i, d[i] = i;
    }
    for (int j = 1; j <= prime[0] && prime[j] * i < N; j++) {
      vis[i * prime[j]] = 1;
      d[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
}
vector<int> vec, g[N];
map<vector<int>, int> mp;
int tot = 0, cnt[N], id[N];
int cac(vector<int> v) {
  int M = 1;
  for (auto x : v) M *= (x + 1);
  return M;
}
void dfs(int sum, int low) {
  if (!mp[vec]) {
    int val = cac(vec);
    if (val > 300) return;
    mp[vec] = ++tot;
    cnt[tot] = val;
  }
  for (int i = low; i >= 1; i--) {
    if (sum + i <= B) {
      vec.push_back(i);
      dfs(sum + i, i);
      vec.pop_back();
    }
  }
}
void build() {
  int edge = 0;
  for (auto p : mp) {
    vector<int> u = p.first, v;
    for (int i = 0; i < u.size(); i++) {
      v = u, v[i]++, sort(v.begin(), v.end(), cmp);
      if (mp.count(v)) {
        g[mp[u]].push_back(mp[v]);
        edge++;
      }
      v = u, v[i]--, sort(v.begin(), v.end(), cmp);
      if (mp.count(v)) {
        if (v[(int)v.size() - 1] == 0) v.pop_back();
        g[mp[u]].push_back(mp[v]);
        edge++;
      }
    }
    v = u;
    v.push_back(1);
    sort(v.begin(), v.end(), cmp);
    if (mp.count(v)) {
      g[mp[u]].push_back(mp[v]);
      edge++;
    }
  }
}
vector<int> fac(int x) {
  vector<int> ans;
  while (x > 1) {
    int t = d[x], c = 0;
    while (x % t == 0) {
      x /= t;
      c++;
    }
    ans.push_back(c);
  }
  sort(ans.begin(), ans.end(), cmp);
  return ans;
}
int dis[302][26002], ans[302][302];
void bfs(int x) {
  int src = mp[fac(x)];
  if (flag[src]) return;
  flag[src] = 1;
  queue<int> q;
  q.push(src);
  for (int i = 1; i < 26000; i++) dis[id[src]][i] = -1;
  dis[id[src]][src] = 0;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (auto v : g[u]) {
      if (dis[id[src]][v] == -1) {
        dis[id[src]][v] = dis[id[src]][u] + 1;
        q.push(v);
      }
    }
  }
  for (int i = 1; i < 26000; i++)
    if (dis[id[src]][i] != -1) {
      ans[id[src]][cnt[i]] = min(ans[id[src]][cnt[i]], dis[id[src]][i]);
    }
}
set<int> st;
int main() {
  init();
  dfs(0, B);
  build();
  for (int i = 0; i <= 300; i++)
    for (int j = 0; j <= 300; j++) ans[i][j] = 1e9;
  for (int i = 1; i < N; i++) {
    int x = mp[fac(i)];
    st.insert(x);
  }
  int bu = 0;
  for (auto x : st) {
    id[x] = ++bu;
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b;
    scanf("%d%d", &a, &b);
    bfs(a);
    bfs(b);
    int ret = 1000;
    int u = id[mp[fac(a)]], v = id[mp[fac(b)]];
    for (int i = 1; i <= 300; i++) {
      ret = min(ret, ans[u][i] + ans[v][i]);
    }
    printf("%d\n", ret);
  }
}