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>
const int N = 1e6, M = 289, K = 4508;
int pn, pr[N + 1], mp[N + 1], tn, divisor[K], numid[N + 1], f[K << 1],
    dis[M][M];
std::vector<int> edge[K], same[K], real2;
std::map<int, int> id2;
std::map<std::vector<int>, int> id;
template <class T1, class T2>
inline bool cmin(T1 &a, const T2 &b) {
  return b < a ? (a = b, true) : false;
}
template <class T1, class T2>
inline bool cmax(T1 &a, const T2 &b) {
  return a < b ? (a = b, true) : false;
}
template <class Type>
Type read() {
  Type a;
  bool b;
  unsigned char c;
  while (c = getchar(), c - '0' > 9 & c != '-')
    ;
  for (a = (b = c == '-') ? 0 : c - '0'; (c = getchar() - '0') <= 9;
       a = a * 10 + c)
    ;
  return b ? -a : a;
}
void search(int max, int sum, int d) {
  static std::vector<int> idx;
  for (int i = 0; i < idx.size(); ++i)
    if (i + 1 == idx.size() || idx[i] != idx[i + 1]) {
      auto cp = idx;
      if (--cp[i] == 0) cp.pop_back();
      int j = id.find(cp)->second;
      edge[tn].push_back(j);
      edge[j].push_back(tn);
    }
  id.emplace(idx, tn);
  divisor[tn++] = d;
  for (int i = 1; i <= max && sum + i <= 22; ++i) {
    idx.push_back(i);
    search(i, sum + i, d * (i + 1));
    idx.pop_back();
  }
}
void flood(int u) {
  int q[K << 1], *qhead = q, *qtail = q;
  memset(f, -1, sizeof(f));
  f[ *qtail++ = u] = 0;
  while (qhead != qtail) {
    u = *qhead++;
    if (u < K) {
      for (int v : same[u])
        if (f[v + K] == -1) f[ *qtail++ = v + K] = f[u] + 1;
      for (int v : edge[u])
        if (f[v] == -1) f[ *qtail++ = v] = f[u] + 1;
    } else {
      for (int v : edge[u - K])
        if (f[v + K] == -1) f[ *qtail++ = v + K] = f[u] + 1;
    }
  }
}
int main() {
  search(22, 0, 1);
  for (int i = 0; i < K; ++i)
    for (int j = 0; j < K; ++j)
      if (divisor[i] == divisor[j]) same[i].push_back(j);
  for (int i = 2; i <= N; ++i) {
    if (mp[i] == 0) mp[i] = pr[pn++] = i;
    for (int j = 0; j < pn && i * pr[j] <= N; ++j) {
      mp[i * pr[j]] = pr[j];
      if (i % pr[j] == 0) break;
    }
  }
  for (int i = 1; i <= N; ++i) {
    std::vector<int> factor;
    for (int j = i; j != 1;) {
      int cnt = 0;
      for (int p = mp[j]; j % p == 0; j /= p) ++cnt;
      factor.push_back(cnt);
    }
    std::sort(factor.begin(), factor.end(), std::greater<int>());
    int x = id[factor];
    if (id2.find(x) == id2.end()) {
      id2.emplace(x, real2.size());
      real2.push_back(x);
    }
    numid[i] = id2[x];
  }
  for (int i = 0; i < M; ++i) {
    flood(real2[i]);
    for (int j = 0; j < M; ++j) dis[i][j] = f[K + real2[j]] - 1;
  }
  int (*rd)() = read<int>;
  for (int t = rd(); t--;) printf("%d\n", dis[numid[rd()]][numid[rd()]]);
  return 0;
}