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;
int read() {
  char c = getchar();
  int d = 0, f = 1;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; d = d * 10 + c - 48, c = getchar())
    ;
  return d * f;
}
char Read() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  return c;
}
int getdigit(char c) { return (c < '0' || c > '9') ? -1e9 : (c - '0'); }
const int inf = 1e9;
const int N = 1000000;
const int Up = 24;
int T, tot, len[N + 1], pn, pr[N + 1], p[N + 1][10], w[10], mk[N + 1];
int TOT, pw[30001][31], t[31], op[30001];
bool cmp(int a, int b) { return a > b; }
void dfs(int x, int s, int la, int S) {
  if (x > Up) {
    ++TOT;
    if (S <= N) op[TOT] = mk[S];
    pw[TOT][0] = x - 1;
    for (int i = 1; i <= x - 1; ++i) pw[TOT][i] = t[i];
    return;
  }
  for (int i = 0; i <= min(la, Up - s); ++i) {
    t[x] = i + 1;
    dfs(x + 1, s + i, i, S);
    S = (int)min(1LL * (N + 1), (long long)S * pr[x]);
  }
}
int cnt, head[80001];
struct edge {
  int to, next, s;
} e[N * 4];
void addedge(int x, int y, int s) {
  e[++cnt] = (edge){y, head[x], s};
  head[x] = cnt;
}
void Addedge(int x, int y, int s) {
  addedge(x, y, s);
  addedge(y, x, s);
}
int stot;
map<long long, int> smp;
void initedge() {
  stot = TOT;
  for (int i = 1; i <= TOT; ++i) {
    for (int j = 1; j <= Up; ++j) t[j] = pw[i][j];
    long long S = 1;
    for (int j = 1; j <= Up; ++j) S = S * t[j];
    int& Smp = smp[S];
    if (!Smp) Smp = ++stot;
    S = Smp;
    addedge(i, S, 0);
    addedge(S, i + 40000, 0);
    for (int j = 1; j <= Up; ++j)
      if (j == Up || t[j] != t[j + 1])
        if (t[j] > 1) {
          t[j]--;
          int L = 1, R = TOT;
          while (L < R) {
            int mid = (L + R) >> 1;
            bool flag = 0;
            for (int I = 1; I <= Up; ++I) {
              if (pw[mid][I] < t[I]) {
                flag = 1;
                break;
              } else if (pw[mid][I] > t[I])
                break;
            }
            if (flag)
              L = mid + 1;
            else
              R = mid;
          }
          Addedge(i, L, 1);
          Addedge(i + 40000, L + 40000, 1);
          t[j]++;
        }
  }
}
int dis[300][80001], q[80001], ans[300][300];
void initdis() {
  for (int i = 1; i <= TOT; ++i)
    if (op[i]) {
      int* Dis = dis[op[i]];
      for (int j = 1; j <= stot + 40000; ++j) Dis[j] = inf;
      Dis[i] = 0;
      int h1 = 1, t = 0;
      q[++t] = i;
      while (h1 <= t) {
        int h2 = t;
        for (int I = h1; I <= h2; ++I)
          for (int j = head[q[I]], y = e[j].to; j; j = e[j].next, y = e[j].to)
            if (e[j].s == 0) {
              if (Dis[y] < inf) continue;
              Dis[y] = Dis[q[I]];
              q[++h2] = y;
            }
        t = h2;
        for (int I = h1; I <= h2; ++I)
          for (int j = head[q[I]], y = e[j].to; j; j = e[j].next, y = e[j].to)
            if (e[j].s == 1) {
              if (Dis[y] < inf) continue;
              Dis[y] = Dis[q[I]] + 1;
              q[++t] = y;
            }
        h1 = h2 + 1;
      }
      for (int j = 1; j <= TOT; ++j)
        if (op[j]) ans[op[i]][op[j]] = min(Dis[j + 40000], Dis[j]);
    }
}
int main() {
  for (int i = 2; i <= N; ++i)
    if (!len[i]) {
      for (int j = i; j <= N; j += i) p[j][++len[j]] = i;
      pr[++pn] = i;
    }
  for (int i = 1; i <= N; ++i) {
    memset(w, 0, sizeof w);
    int s = i;
    for (int j = 1; j <= 10; ++j) w[j] = 1;
    for (int j = 1; j <= len[i]; ++j)
      while (s % p[i][j] == 0) w[j]++, s /= p[i][j];
    sort(w + 1, w + len[i] + 1, cmp);
    s = 1;
    for (int j = 1; j <= len[i]; ++j)
      for (int k = 1; k <= w[j] - 1; ++k) s = (long long)s * pr[j];
    if (s == i)
      ++tot, mk[i] = tot;
    else
      mk[i] = mk[s];
  }
  TOT = 0;
  dfs(1, 0, Up, 1);
  initedge();
  initdis();
  T = read();
  while (T--) {
    int x = read(), y = read();
    x = mk[x], y = mk[y];
    printf("%d\n", ans[x][y]);
  }
}