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 = 1000001;
const int M = 10;
const int D = 300;
int pr[10] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
vector<vector<char> > mp;
vector<char> cur(M);
int fp[N];
int calc(vector<char> &v) {
  int res = 1;
  for (auto x : v) res *= x + 1;
  return res;
}
void gen(int i, int val) {
  if (calc(cur) > D) return;
  if (i == cur.size()) {
    mp.push_back(cur);
    return;
  }
  int p = 1;
  for (char t = i ? cur[i - 1] : 0;; ++t) {
    if (val * (long long)p > 1e9) break;
    val *= p;
    cur[i] = t;
    gen(i + 1, val);
    cur[i] = 0;
    p = pr[i];
  }
}
vector<char> get(int a) {
  vector<char> cur;
  while (a != 1) {
    int p = fp[a];
    if (p == 0) {
      cur.push_back(1);
      break;
    }
    cur.push_back(0);
    while (a % p == 0) {
      ++cur.back();
      a /= p;
    }
  }
  cur.resize(M, 0);
  sort(cur.begin(), cur.end());
  return cur;
}
long long Hash(vector<char> &w) {
  long long h = 0;
  for (auto z : w) h = h * 64 + z;
  return h;
}
int cost[D + 1][1024];
vector<vector<int> > g;
vector<int> F;
set<long long> good;
int q[1234], qf, ql;
int BFS(int src, int t) {
  if (cost[t][src] != -1) return cost[t][src];
  for (int d = 1; d <= D; ++d) {
    cost[d][src] = 1e9;
  }
  int u = src;
  q[qf = ql = 0] = u;
  vector<int> vis(g.size(), -1);
  vis[u] = 0;
  while (qf <= ql) {
    auto u = q[qf];
    ++qf;
    cost[F[u]][src] = min(cost[F[u]][src], vis[u]);
    for (auto v : g[u])
      if (vis[v] == -1) {
        vis[v] = vis[u] + 1;
        q[++ql] = v;
      }
  }
  return cost[t][src];
}
int main() {
  reverse(pr, pr + 10);
  gen(0, 1);
  sort(mp.begin(), mp.end());
  for (auto &v : mp) good.insert(Hash(v));
  for (int i = 2; i < N; ++i)
    if (fp[i] == 0)
      for (int j = i + i; j < N; j += i)
        if (fp[j] == 0) fp[j] = i;
  for (int i = 0; i < mp.size(); ++i) F.push_back(calc(mp[i]));
  g.resize(mp.size());
  for (int i = 0; i < mp.size(); ++i) {
    for (int j = 0; j < mp.size(); ++j) {
      int freq[64] = {};
      for (auto x : mp[i]) ++freq[x];
      for (auto y : mp[j]) --freq[y];
      int diff = 0;
      int f = -1, l = -1;
      for (int k = 0; k < 64; ++k) {
        diff += abs(freq[k]);
        if (freq[k])
          if (f == -1) f = k;
        if (freq[k]) l = k;
      }
      if (diff == 2 && abs(f - l) == 1) g[i].push_back(j);
    }
  }
  memset(cost, -1, sizeof(cost));
  clock_t T = clock();
  int t;
  scanf("%d", &t);
  while (t--) {
    int a, b;
    scanf("%d%d", &a, &b);
    auto A = lower_bound(mp.begin(), mp.end(), get(a)) - mp.begin();
    auto B = lower_bound(mp.begin(), mp.end(), get(b)) - mp.begin();
    int res = 1e9;
    for (int d = 1; d <= D; ++d) res = min(res, BFS(A, d) + BFS(B, d));
    printf("%d\n", res);
  }
  fprintf(stderr, "%.3lf\n", double(clock() - T) / CLOCKS_PER_SEC);
  return 0;
}