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 n = 0;
  char c;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - 48;
  return n;
}
const int N = 1e6, mn = 3e3;
int i, j, t, a, b, cnt, cx, cy, s1, s2, x[10], y[10], A[10], cn;
int c[N], f[N + 5], w[N + 5];
int B[N + 5], num, g[mn + 5];
int C[8], P[8][mn][8], Co[305][mn + 5], Z[305][mn + 5], Zt[305];
int ans;
void cmin(int &x, int y) { x = (x < y ? x : y); }
void dfs(int x, int y, int s) {
  if (y > 22 || s > mn) return;
  C[x]++;
  int i;
  for (i = 1; i <= x; i++) P[x][C[x]][i] = A[i];
  if (x == 7) return;
  for (i = 0; i <= A[x]; i++) A[x + 1] = i, dfs(x + 1, y + i, s * (i + 1));
}
void pre() {
  for (i = 2; i <= N; i++) {
    if (!f[i]) c[++cnt] = i, f[i] = i, w[i] = 1;
    for (int p = c[j = 1]; i * p <= N; p = c[++j]) {
      f[i * p] = p, w[i * p] = w[i] + 1;
      if (i % p == 0) break;
    }
  }
  for (i = 2; i <= mn; i++) {
    g[i] = i - 1;
    int m = sqrt(i);
    for (j = 2; j <= m; j++)
      if (i % j == 0) cmin(g[i], g[i / j] + g[j]);
  }
  A[0] = 22;
  dfs(0, 0, 1);
}
bool cmp(int x, int y) { return x > y; }
void work(int x) {
  B[x] = ++num;
  int i;
  memset(Co[num], 127 / 3, sizeof(Co[num]));
  for (i = 1; i <= C[cn]; i++) {
    int co = 0, s = 1, p;
    for (j = 1; j <= cn; j++)
      p = P[cn][i][j], co += abs(A[j] - p), s *= (p + 1);
    if (co > 10) continue;
    for (j = 1; j * s <= mn; j++) cmin(Co[num][j * s], co + g[j]);
  }
  for (i = 1; i <= mn; i++)
    if (Co[num][i] <= 10) Z[num][++Zt[num]] = i;
}
int main() {
  pre();
  t = read();
  for (; t--;) {
    a = read(), b = read();
    for (cx = 0; a > 1;) {
      x[++cx] = 0;
      for (int p = f[a]; a % p == 0; a /= p) x[cx]++;
    }
    sort(x + 1, x + 1 + cx, cmp);
    s1 = 1;
    for (i = 1; i <= cx; i++) s1 *= pow(c[i], x[i]);
    if (!B[s1]) {
      cn = cx;
      for (i = 1; i <= cn; i++) A[i] = x[i];
      work(s1);
    }
    s1 = B[s1];
    for (cy = 0; b > 1;) {
      y[++cy] = 0;
      for (int p = f[b]; b % p == 0; b /= p) y[cy]++;
    }
    sort(y + 1, y + 1 + cy, cmp);
    s2 = 1;
    for (i = 1; i <= cy; i++) s2 *= pow(c[i], y[i]);
    if (!B[s2]) {
      cn = cy;
      for (i = 1; i <= cn; i++) A[i] = y[i];
      work(s2);
    }
    s2 = B[s2];
    ans = 20;
    for (i = 1; i <= Zt[s1]; i++) {
      int p = Z[s1][i];
      cmin(ans, Co[s1][p] + Co[s2][p]);
    }
    printf("%d\n", ans);
  }
}