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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
using namespace std;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
const int xn = 1e6 + 10;
const int xm = 1e3 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const long long INF = 1e15 + 10;
const int mod = 1e9 + 7;
const int base = 257;
int qq, a[xm], n, c[xm], dist[xm][xm], ans;
bool pr[xn];
vector<int> prm, vec[xm], vec2, adj[xm], mg[xn];
unordered_map<int, int> mp;
queue<int> q;
void solve(int ptr = 0, long long val = 1, int res = 1) {
  for (int i = 0; i < ptr; ++i) vec[n].push_back(a[i]);
  mp[val] = n, c[n++] = res;
  for (int i = 2; i < 40; ++i) {
    val *= prm[ptr];
    if (val > 1e8 || (ptr && i > a[ptr - 1])) break;
    a[ptr] = i, solve(ptr + 1, val, res * i);
  }
}
int check() {
  sort(vec2.begin(), vec2.end()), reverse(vec2.begin(), vec2.end());
  long long res = 1;
  for (int i = 0; i < int(vec2.size()); ++i)
    for (int j = 1; j < vec2[i]; ++j) res *= prm[i];
  if (res > 1e8) return -1;
  return mp[res];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 2; i < xn; ++i) {
    if (pr[i]) continue;
    prm.push_back(i);
    for (int j = i; j < xn; j += i) pr[j] = true, mg[j].push_back(i);
  }
  solve();
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= int(vec[i].size()); ++j) {
      vec2.clear();
      for (int k = 0; k < int(vec[i].size()); ++k) {
        if (k == j)
          vec2.push_back(vec[i][k] + 1);
        else
          vec2.push_back(vec[i][k]);
      }
      if (j == int(vec[i].size())) vec2.push_back(2);
      int id = check();
      if (id == -1) continue;
      adj[i].push_back(id);
      adj[id].push_back(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) dist[i][j] = inf;
    for (int j = 0; j < n; ++j)
      if (c[i] == c[j]) dist[i][j] = 0, q.push(j);
    while (int(q.size())) {
      int v = q.front();
      q.pop();
      for (int u : adj[v])
        if (dist[i][u] == inf) dist[i][u] = dist[i][v] + 1, q.push(u);
    }
  }
  cin >> qq;
  while (qq--) {
    int x, y;
    cin >> x >> y;
    vec2.clear();
    for (int z : mg[x]) {
      int t = 1, w = x;
      while (w % z == 0) w /= z, ++t;
      vec2.push_back(t);
    }
    int id1 = check();
    vec2.clear();
    for (int z : mg[y]) {
      int t = 1, w = y;
      while (w % z == 0) w /= z, ++t;
      vec2.push_back(t);
    }
    int id2 = check();
    ans = inf;
    for (int i = 0; i < n; ++i) ans = min(ans, dist[i][id1] + dist[i][id2]);
    cout << ans << '\n';
  }
  return 0;
}