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;
map<vector<int>, int> M;
int dv[2505];
int nxt;
vector<int> vec;
int p[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
void dfs(long long num, int last, int nxtt, int mul) {
  if (num > 10000000000) return;
  if (M.find(vec) == M.end()) {
    dv[nxt] = mul;
    M[vec] = nxt++;
  }
  for (int i = 1; i <= last; i++) {
    num *= p[nxtt];
    if (num > 10000000000) return;
    vec.push_back(i);
    dfs(num, i, nxtt + 1, mul * (i + 1));
    vec.pop_back();
  }
}
int dist[2505][2505];
int D[2505][2505];
bool used[2505][2505];
vector<int> edge[2505];
int t;
int go[1000005];
int main() {
  dfs(1, 31, 0, 1);
  for (map<vector<int>, int>::iterator it = M.begin(); it != M.end(); ++it) {
    vector<int> vec = it->first;
    int id = it->second;
    for (int i = 0; i <= vec.size(); i++) {
      vector<int> vec2;
      for (int j = 0; j < vec.size(); j++) vec2.push_back(vec[j] + (i == j));
      if (i == vec.size()) vec2.push_back(1);
      sort(vec2.begin(), vec2.end(), greater<int>());
      if (M.find(vec2) != M.end()) {
        edge[id].push_back(M[vec2]);
      }
      if (i == vec.size()) break;
      vec2.clear();
      for (int j = 0; j < vec.size(); j++) vec2.push_back(vec[j] - (i == j));
      sort(vec2.begin(), vec2.end(), greater<int>());
      while (vec2[vec2.size() - 1] == 0) vec2.pop_back();
      if (M.find(vec2) != M.end()) {
        edge[id].push_back(M[vec2]);
      }
    }
  }
  for (int a = 0; a < 2505; a++)
    for (int b = 0; b < 2505; b++) dist[a][b] = D[a][b] = 1000000000;
  for (int i = 0; i < nxt; i++) {
    dist[i][i] = 0;
    queue<int> que;
    que.push(i);
    while (!que.empty()) {
      int q = que.front();
      que.pop();
      if (used[i][q]) continue;
      used[i][q] = 1;
      for (int ii = 0; ii < edge[q].size(); ii++) {
        int to = edge[q][ii];
        dist[i][to] = min(dist[i][to], dist[i][q] + 1);
        if (!used[i][to]) {
          que.push(to);
        }
      }
    }
    for (int j = 0; j < nxt; j++) {
      D[i][dv[j]] = min(D[i][dv[j]], dist[i][j]);
    }
  }
  for (int i = 2; i <= 1000000; i++) {
    if (go[i]) continue;
    for (int j = 2; i * j <= 1000000; j++) {
      go[i * j] = i;
    }
  }
  scanf("%d", &t);
  for (int ii = 0; ii < t; ii++) {
    int a, b;
    scanf("%d%d", &a, &b);
    map<int, int> A, B;
    while (a > 1) {
      if (go[a] == 0) {
        A[a]++;
        break;
      }
      A[go[a]]++;
      a /= go[a];
    }
    while (b > 1) {
      if (go[b] == 0) {
        B[b]++;
        break;
      }
      B[go[b]]++;
      b /= go[b];
    }
    vector<int> va, vb;
    for (map<int, int>::iterator it = A.begin(); it != A.end(); it++) {
      va.push_back(it->second);
    }
    for (map<int, int>::iterator it = B.begin(); it != B.end(); it++) {
      vb.push_back(it->second);
    }
    sort(va.begin(), va.end(), greater<int>());
    sort(vb.begin(), vb.end(), greater<int>());
    int xa = M[va];
    int xb = M[vb];
    int ans = 1000000000;
    for (int i = 0; i < 2505; i++) {
      ans = min(ans, D[xa][i] + D[xb][i]);
    }
    printf("%d\n", ans);
  }
}