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;
vector<int> all[510];
multiset<int> factor[1000010];
vector<int> from[1000010];
int dist[510][30010], my[1000010];
int prime[1000010], tot, vis[1000010], minp[1000010], cnt[1000010],
    fnum[1000010];
queue<int> q;
vector<pair<int, int> > query;
map<multiset<int>, int> ids;
int TOT;
void dfs(multiset<int> &s, int mul, int last, int b) {
  ids[s];
  for (int i = b; i <= last / mul; i++) {
    s.insert(i - 1);
    dfs(s, mul * i, last, i);
    s.erase(s.find(i - 1));
  }
}
void get_pre() {
  multiset<int> aaa;
  dfs(aaa, 1, 500, 2);
  for (int i = 2; i <= 1000000; i++) {
    if (!vis[i]) prime[tot++] = i, minp[i] = i, cnt[i] = 1, fnum[i] = 2;
    for (int j = 0; j < tot && 1ll * i * prime[j] <= 1000000; j++) {
      int x = i * prime[j];
      vis[x] = 1, minp[x] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
  int maxj = 0;
  for (int i = 1; i <= 1000000; i++) {
    int x = i;
    int cnt = 0, last = -1;
    int mul = 1;
    while (x > 1) {
      if (minp[x] != last) {
        last = minp[x], mul *= cnt + 1;
        if (cnt != 0) factor[i].insert(cnt);
        cnt = 1;
      } else
        cnt++;
      x /= minp[x];
    }
    mul *= cnt + 1, factor[i].insert(cnt);
    maxj = max(maxj, mul);
  }
  for (auto it = ids.begin(); it != ids.end(); it++) {
    it->second = TOT++;
    int mul = 1;
    for (int x : it->first) {
      mul *= x + 1;
    }
    all[mul].push_back(it->second);
  }
  vector<pair<multiset<int>, int> > v(ids.begin(), ids.end());
  for (auto it = v.begin(); it != v.end(); it++) {
    auto now = it->first;
    int u = it->second;
    for (auto x = it->first.begin(); x != it->first.end(); x++) {
      int val = *x;
      now.erase(now.find(val));
      if (val != 1) now.insert(val - 1);
      if (ids.count(now))
        from[u].push_back(ids[now]), from[ids[now]].push_back(u);
      if (val != 1) now.erase(now.find(val - 1));
      now.insert(val);
    }
    for (auto x = it->first.begin(); x != it->first.end(); x++) {
      int val = *x;
      now.erase(now.find(val));
      now.insert(val + 1);
      if (ids.count(now))
        from[u].push_back(ids[now]), from[ids[now]].push_back(u);
      now.erase(now.find(val + 1));
      now.insert(val);
    }
    now.insert(1);
    if (ids.count(now))
      from[u].push_back(ids[now]), from[ids[now]].push_back(u);
  }
  memset(dist, 0x3f3f3f3f, sizeof(dist));
  for (int t = 1; t <= 500; t++) {
    for (int i = 0; i < all[t].size(); i++) {
      int x = all[t][i];
      q.push(x), vis[x] = t, dist[t][x] = 0;
    }
    int tot = 0;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      tot++;
      for (int i = 0; i < from[x].size(); i++) {
        int v = from[x][i];
        if (vis[v] == t) continue;
        q.push(v), vis[v] = t, dist[t][v] = dist[t][x] + 1;
      }
    }
  }
}
int ans[100010];
void read() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int a, b;
    scanf("%d%d", &a, &b);
    int x = ids[factor[a]], y = ids[factor[b]];
    int ans = 0x3f3f3f3f;
    for (int i = 1; i <= 500; i++) {
      ans = min(ans, dist[i][x] + dist[i][y]);
    }
    printf("%d\n", ans);
  }
}
void print() {
  for (int i = 0; i < query.size(); i++) {
    printf("%d\n", ans[i]);
    for (int j = 0; j < ans[i]; j++) {
      printf("%d\n", j);
    }
  }
}
int main() {
  get_pre();
  read();
  return 0;
}