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 mod = 1e9 + 7;
struct fastio {
  char s[100000];
  int it, len;
  fastio() { it = len = 0; }
  inline char get() {
    if (it < len) return s[it++];
    it = 0;
    len = fread(s, 1, 100000, stdin);
    if (len == 0)
      return EOF;
    else
      return s[it++];
  }
  bool notend() {
    char c = get();
    while (c == ' ' || c == '\n') c = get();
    if (it > 0) it--;
    return c != EOF;
  }
} _buff;
inline long long getnum() {
  long long r = 0;
  bool ng = 0;
  char c;
  c = _buff.get();
  while (c != '-' && (c < '0' || c > '9')) c = _buff.get();
  if (c == '-') ng = 1, c = _buff.get();
  while (c >= '0' && c <= '9') r = r * 10 + c - '0', c = _buff.get();
  return ng ? -r : r;
}
template <class T>
inline void putnum(T x) {
  if (x < 0) putchar('-'), x = -x;
  register short a[20] = {}, sz = 0;
  while (x) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
inline char getreal() {
  char c = _buff.get();
  while (c <= 32) c = _buff.get();
  return c;
}
long long qpow(long long x, long long k) {
  return k == 0 ? 1
                : 1ll * qpow(1ll * x * x % mod, k >> 1) * (k & 1 ? x : 1) % mod;
}
const int N = 7;
const int maxst = 333;
int pfac[8] = {2, 3, 5, 7, 11, 13, 17};
int Tn;
int tot;
int st[maxst];
map<int, int> stid;
int getst(int x) {
  int seq[10];
  int sn = 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int cnt = 0;
      while (x % i == 0) {
        x /= i;
        cnt++;
      }
      seq[sn++] = cnt;
    }
  }
  if (x > 1) seq[sn++] = 1;
  sort(seq, seq + sn);
  reverse(seq, seq + sn);
  x = 1;
  for (int i = 0; i < sn; i++) {
    for (int j = 0; j < seq[i]; j++) x = x * pfac[i];
  }
  return x;
}
int getfn(int x) {
  int seq[10];
  int sn = 0;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int cnt = 0;
      while (x % i == 0) {
        x /= i;
        cnt++;
      }
      seq[sn++] = cnt;
    }
  }
  if (x > 1) seq[sn++] = 1;
  int ret = 1;
  for (int i = 0; i < sn; i++) ret *= seq[i] + 1;
  return ret;
}
const int cost_bound = 10;
const int nfn_bound = 2333;
int dis[maxst][nfn_bound];
map<int, int> mp;
void dfs(int i, int x, int mx, int cost, int fn, long long nfn) {
  if (i == N) {
    if (stid.find(x) == stid.end()) {
      stid[x] = tot++;
    }
    int id = stid[x];
    dis[id][nfn] = min(dis[id][nfn], cost);
    return;
  }
  for (int c = 0; c <= mx; c++) {
    if (x <= 1000000) {
      for (int j = 0; j <= c + 10; j++) {
        if (abs(j - c) + cost <= cost_bound) {
          if (nfn * (j + 1) <= nfn_bound) {
            dfs(i + 1, x, c, abs(j - c) + cost, fn * (c + 1), nfn * (j + 1));
          }
        }
      }
    } else
      break;
    x = x * pfac[i];
  }
}
int getid(int x) {
  if (stid.find(x) == stid.end())
    return tot;
  else
    return stid[x];
}
int g[maxst], tab[maxst][maxst];
map<int, int> fid;
int main() {
  memset(dis, 20, sizeof(dis));
  dfs(0, 1, 100, 0, 1, 1);
  if (0) cout << "tot=" << tot << endl;
  int q;
  q = getnum();
  while (q--) {
    int x, y;
    x = getnum(), y = getnum();
    x = getst(x);
    y = getst(y);
    x = getid(x);
    y = getid(y);
    assert(x < tot);
    assert(y < tot);
    int ans = 1e9;
    for (int i = 1; i < nfn_bound; i++) ans = min(ans, dis[x][i] + dis[y][i]);
    putnum(ans), putchar('\n');
  }
  return 0;
}