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;
const int inf = 0x7fffffff;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int read() {
  int x = 0, f = 1;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch & 15);
    ch = getchar();
  }
  if (f)
    return x;
  else
    return -x;
}
const int N = 1000010, M = 3010, mod = 233;
bool used[N];
int sta[M], zt[N];
int ls[M], dis[M][M];
int cnt, a[M][10], f[M], s[N], g[N][10];
int prime[10] = {0, 2, 3, 5, 7, 11, 13, 17, 19};
map<unsigned long long, int> mp;
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 * mod + sta[i];
    mp[t] = cnt;
    return;
  }
  for (int i = 0; i <= sta[x - 1]; i++) {
    sta[x] = i;
    dfs(x + 1, d * (i + 1), sum);
    sum *= prime[x];
    if (sum > 200000000) break;
  }
}
inline int init(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 * mod + b[i];
  return mp[t];
}
int main() {
  sta[0] = 30;
  dfs(1, 1, 1);
  memset(dis, 63, 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;
      long long x = 0;
      ++a[i][j];
      for (int k = 1; k <= 8; k++)
        if (a[i][k]) x = x * mod + a[i][k];
      --a[i][j];
      if (mp.count(x)) {
        int t = mp[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)
            dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
  for (int i = 1; i <= cnt; i++) {
    for (int j = 1; j <= cnt; j++) ls[j] = dis[i][j], dis[i][j] = inf;
    for (int j = 1; j <= cnt; j++) dis[i][f[j]] = min(dis[i][f[j]], ls[j]);
  }
  for (int i = 2; i <= N - 10; i++) {
    if (s[i]) continue;
    for (int x = i; x <= N - 10; x += i) g[x][++s[x]] = i;
  }
  int size = 0;
  for (int i = 1; i <= cnt; i++)
    if (!used[f[i]]) used[f[i]] = 1, zt[++size] = f[i];
  int T = read();
  while (T--) {
    int x = read(), y = read();
    x = init(x), y = init(y);
    int ans = inf;
    for (int i = 1; i <= size; i++)
      ans = min(ans, dis[x][zt[i]] + dis[y][zt[i]]);
    printf("%d\n", ans);
  }
  return 0;
}