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;
template <class T, class T2>
inline int chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline int chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
const int MAXM = 500;
const int bound = (int)1e6;
const int MAGIC = 24;
int lp[MAXN];
vector<int> pr;
set<vector<int> > st;
void prepare() {
  for (int i = 2; i <= bound; i++) {
    if (lp[i] == 0) lp[i] = i, pr.push_back(i);
    for (int j = 0;
         j < (int)pr.size() && i * 1ll * pr[j] <= bound && pr[j] <= lp[i]; j++)
      lp[i * pr[j]] = pr[j];
  }
}
vector<vector<int> > li;
vector<int> get(int i) {
  int x = i;
  vector<int> curr;
  while (x != 1) {
    int d = lp[x], cnt = 0;
    while (x % d == 0) x /= d, cnt++;
    curr.push_back(cnt);
  }
  sort(curr.begin(), curr.end());
  return curr;
}
void read() {
  for (int i = 1; i <= bound; i++) {
    int x = i;
    vector<int> curr;
    while (x != 1) {
      int d = lp[x], cnt = 0;
      while (x % d == 0) x /= d, cnt++;
      curr.push_back(cnt);
    }
    sort(curr.begin(), curr.end());
    st.insert(curr);
  }
  for (auto it : st) li.push_back(it);
}
int N, K;
int dp[MAXM][1 << 16];
int get_id(const vector<vector<int> > &li, vector<int> p) {
  return lower_bound(li.begin(), li.end(), p) - li.begin();
}
vector<pair<int, int> > same;
vector<vector<int> > all_vec;
vector<int> curr_Vec;
void gen(int sum, int last = 1) {
  all_vec.push_back(curr_Vec);
  if (sum == 0) return;
  for (int curr = last; curr <= sum; curr++) {
    curr_Vec.push_back(curr);
    gen(sum - curr, curr);
    curr_Vec.pop_back();
  }
}
int dist[MAXN];
vector<int> adj[MAXN];
vector<int> possible_divs;
int divs(vector<int> &l) {
  int r = 1;
  for (int i : l) r *= (i + 1);
  return r;
}
int get_pos(int x) {
  return lower_bound(possible_divs.begin(), possible_divs.end(), x) -
         possible_divs.begin();
}
int D[MAXN];
void solve() {
  gen(MAGIC);
  N = li.size();
  K = all_vec.size();
  for (int i = 0; i < K; i++) {
    for (int p = 0; p < (int)all_vec[i].size(); p++) {
      {
        vector<int> nw = all_vec[i];
        nw[p]--;
        sort(nw.begin(), nw.end());
        if (*nw.begin() == 0) nw.erase(nw.begin());
        int id = get_id(all_vec, nw);
        if (id != K && all_vec[id] == nw) {
          adj[i].push_back(id);
          adj[id].push_back(i);
        }
      }
      {
        vector<int> nw = all_vec[i];
        nw[p]++;
        sort(nw.begin(), nw.end());
        int id = get_id(all_vec, nw);
        if (id != K && all_vec[id] == nw) {
          adj[i].push_back(id);
          adj[id].push_back(i);
        }
      }
    }
    {
      vector<int> nw = all_vec[i];
      nw.push_back(1);
      sort(nw.begin(), nw.end());
      int id = get_id(all_vec, nw);
      if (id != K && all_vec[id] == nw) {
        adj[i].push_back(id);
        adj[id].push_back(i);
      }
    }
  }
  for (int i = 0; i < K; i++) possible_divs.push_back(divs(all_vec[i]));
  sort(possible_divs.begin(), possible_divs.end());
  possible_divs.erase(unique(possible_divs.begin(), possible_divs.end()),
                      possible_divs.end());
  for (int i = 0; i < K; i++) D[i] = get_pos(divs(all_vec[i]));
  for (int ii = 0; ii < N; ii++) {
    int root = get_id(all_vec, li[ii]);
    for (int i = 0; i < K; i++) dist[i] = -1;
    queue<int> q;
    q.push(root);
    dist[root] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int v : adj[u])
        if (dist[v] == -1) {
          dist[v] = dist[u] + 1;
          q.push(v);
        }
    }
    for (int iii = 0; iii < (int)possible_divs.size(); iii++)
      dp[ii][iii] = MAXN;
    for (int j = 0; j < K; j++) chkmin(dp[ii][D[j]], dist[j]);
  }
  int t;
  cin >> t;
  while (t--) {
    int a, b;
    cin >> a >> b;
    vector<int> A = get(a), B = get(b);
    a = lower_bound(li.begin(), li.end(), A) - li.begin();
    b = lower_bound(li.begin(), li.end(), B) - li.begin();
    int answer = MAXN;
    for (int i = 0; i < (int)possible_divs.size(); i++)
      chkmin(answer, dp[a][i] + dp[b][i]);
    cout << answer << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  prepare();
  read();
  solve();
  return 0;
}