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 <typename T>
void maxtt(T &t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T &t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
map<vector<int>, int> mp;
vector<vector<int>> V;
int id[1000005];
int ps[1000005], f[1005], g[1005];
int dis[305][1005], ans[300][300];
int gid(vector<int> &vp) {
  if (mp.find(vp) != mp.end()) return mp[vp];
  V.push_back(vp);
  mp[vp] = V.size() - 1;
  return V.size() - 1;
}
void fmain(int ID) {
  int N = 1000000;
  for (int i = 2; i <= N; i++)
    if (!ps[i]) {
      for (int j = i; j <= N; j += i) {
        ps[j] = i;
      }
    }
  for (int i = 1; i <= N; i++) {
    map<int, int> vp;
    for (int j = i; j > 1; j /= ps[j]) {
      vp[ps[j]]++;
    }
    vector<int> vs;
    for (auto &p : vp) vs.push_back(p.second + 1);
    sort(vs.begin(), vs.end());
    id[i] = gid(vs);
  }
  for (int(i) = 0; (i) < (int)(V.size()); (i)++) {
    for (int(j) = 0; (j) < (int)(1000); (j)++) f[j] = N;
    f[1] = 0;
    for (int &y : V[i]) {
      swap(f, g);
      for (int(j) = 0; (j) < (int)(1000); (j)++) f[j] = N;
      for (int k = 1; k <= y + 10; k++) {
        for (int p = 1; p * k < 1000; p++) mintt(f[p * k], g[p] + abs(y - k));
      }
    }
    for (int(j) = 1; (j) <= (int)(999); (j)++)
      if (f[j] < N) {
        for (int k = 2; k * j < 1000; k++) mintt(f[k * j], f[j] + k - 1);
      }
    for (int(j) = 0; (j) < (int)(1000); (j)++) dis[i][j] = f[j];
  }
  for (int(i) = 0; (i) < (int)(V.size()); (i)++)
    for (int(j) = 0; (j) < (int)(V.size()); (j)++) {
      ans[i][j] = N;
      for (int(k) = 0; (k) < (int)(1000); (k)++)
        mintt(ans[i][j], dis[i][k] + dis[j][k]);
    }
  scanf("%d", &n);
  for (int(i) = 1; (i) <= (int)(n); (i)++) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", ans[id[x]][id[y]]);
  }
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}