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;
inline int read() {
  int f = 1, sum = 0;
  char x = getchar();
  for (; (x < '0' || x > '9'); x = getchar())
    if (x == '-') f = -1;
  for (; x >= '0' && x <= '9'; x = getchar()) sum = sum * 10 + x - '0';
  return f * sum;
}
bool vis[1000005];
int sta[3005], zt[1000005];
int A[3005], dis[3005][3005];
int cnt, a[3005][10], f[3005], s[1000005], g[1000005][10];
int x_[10] = {0, 2, 3, 5, 7, 11, 13, 17, 19};
unordered_map<unsigned long long, int> st;
inline void max(int &x, int y) {
  if (x < y) x = y;
}
inline void min(int &x, int y) {
  if (x > y) x = y;
}
inline void dfs(int x, int d, long long sum) {
  if (x == 9) {
    f[++cnt] = d;
    for (int i = 0; i <= 8; ++i) a[cnt][i] = sta[i];
    unsigned long long t = 0;
    for (int i = 1; i <= 8; ++i)
      if (sta[i]) t = t * 76543 + sta[i];
    st[t] = cnt;
    return;
  }
  for (int i = 0; i <= sta[x - 1]; ++i) {
    sta[x] = i;
    dfs(x + 1, d * (i + 1), sum);
    sum *= x_[x];
    if (sum > 200000000) break;
  }
}
inline int get_(int x) {
  int now = x;
  int b[10] = {0};
  for (int i = 1; i <= s[x]; ++i) {
    int y = g[x][i];
    while (!(now % y)) now /= y, ++b[i];
  }
  sort(b + 1, b + s[x] + 1);
  unsigned long long t = 0;
  for (int i = s[x]; i >= 1; --i) t = t * 76543 + b[i];
  return st[t];
}
int main() {
  sta[0] = 30;
  dfs(1, 1, 1);
  memset(dis, 0x3f, sizeof(dis));
  for (int i = 1; i <= cnt; ++i) dis[i][i] = 0;
  for (int i = 1; i <= cnt; ++i) {
    for (int j = 1; j <= 8; ++j) {
      if (a[i][j] + 1 > a[i][j - 1]) continue;
      unsigned long long x = 0;
      ++a[i][j];
      for (int k = 1; k <= 8; ++k)
        if (a[i][k]) x = x * 76543 + a[i][k];
      --a[i][j];
      if (st.count(x)) {
        int t = st[x];
        dis[i][t] = dis[t][i] = 1;
      }
    }
  }
  for (int i = 1; i <= cnt; ++i)
    for (int j = 1; j <= cnt; ++j)
      if (dis[j][i] < 100)
        for (int k = 1; k <= cnt; ++k)
          if (dis[i][k] < 100) min(dis[j][k], dis[j][i] + dis[i][k]);
  for (int i = 1; i <= cnt; ++i) {
    for (int j = 1; j <= cnt; ++j) A[j] = dis[i][j], dis[i][j] = 1e9;
    for (int j = 1; j <= cnt; ++j) min(dis[i][f[j]], A[j]);
  }
  for (int i = 2; i <= 1000005 - 5; ++i) {
    if (s[i]) continue;
    int x = i;
    while (x + 4 < 1000005) g[x][++s[x]] = i, x += i;
  }
  int size = 0;
  for (int i = 1; i <= cnt; ++i)
    if (!vis[f[i]]) vis[f[i]] = 1, zt[++size] = f[i];
  int Test_ = read();
  while (Test_--) {
    int x = read(), y = read();
    x = get_(x), y = get_(y);
    int ans = 1e9;
    for (int i = 1; i <= size; ++i) min(ans, dis[x][zt[i]] + dis[y][zt[i]]);
    printf("%d\n", ans);
  }
}