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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6 + 1;
const long long mod = 1e9 + 7;
const long double PI = acos((long double)-1);
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
int q;
map<long long, int> mp;
vector<int> chan[maxn];
long long vect[maxn];
long long num[5000];
int san[maxn];
bool bad[maxn];
int sz = 0;
map<int, int> cunt;
vector<int> fuck[810];
void build(int tot, int lim, long long chan) {
  if (!mp.count(chan)) mp[chan] = ++sz;
  for (long long i = 1; i <= lim && i <= tot; i++) {
    chan <<= 1LL;
    chan <<= i;
    chan |= (1LL << i) - 1;
    build(tot - i, i, chan);
    chan >>= (i + 1);
  }
}
vector<int> adj[5000];
int dist[810][5000];
void make() {
  for (int i = 1; i <= sz; i++) {
    long long val = num[i];
    if (mp.count(((val << 2LL) | 1))) adj[i].push_back(mp[((val << 2LL) | 1)]);
    long long u = val >> 1LL;
    u >>= (u & -u);
    u <<= 1, u |= 1;
    adj[i].push_back(mp[u]);
    adj[i].push_back(mp[val >> 1LL]);
    for (long long j = 0; j < 46; j++) {
      long long u =
          (val >> j) << (j + 1) | (1LL << j) | (val & ((1LL << j) - 1));
      if (abs(__builtin_popcount(u) - __builtin_popcount(val)) <= 1 and
          u != val)
        if (mp.count(u)) adj[i].push_back(mp[u]);
      u = (val >> (j + 1)) << (j) | (val & ((1LL << j) - 1));
      if (abs(__builtin_popcount(u) - __builtin_popcount(val)) <= 1 and
          u != val and (val & (1LL << j)))
        if (mp.count(u)) adj[i].push_back(mp[u]);
    }
  }
}
int f(int v) {
  long long x = num[v];
  int cnt = 0;
  int res = 1;
  for (long long i = 1; i <= x; i <<= 1LL) {
    if (i & x)
      cnt++;
    else
      res *= (cnt + 1), cnt = 0;
  }
  res *= (cnt + 1);
  return res;
}
void spfa(int x) {
  queue<int> q;
  memset(dist[x], -1, sizeof dist[x]);
  for (auto v : fuck[x]) dist[x][v] = 0, q.push(v);
  while (q.size()) {
    int v = q.front();
    q.pop();
    for (auto u : adj[v])
      if (dist[x][u] == -1) dist[x][u] = dist[x][v] + 1, q.push(u);
  }
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 0; i < maxn; i++) san[i] = i;
  for (int i = 2; i <= 1000; i++)
    if (!bad[i]) {
      for (int j = i; j < maxn; j += i) {
        int cnt = 0;
        bad[j] = 1;
        while (san[j] % i == 0) san[j] /= i, cnt++;
        chan[j].push_back(cnt);
      }
    }
  for (int i = 1; i < maxn; i++) {
    if (san[i] ^ 1) chan[i].push_back(1);
    sort(chan[i].begin(), chan[i].end());
    reverse(chan[i].begin(), chan[i].end());
    for (int x : chan[i])
      vect[i] <<= 1LL, vect[i] <<= x, vect[i] |= (1LL << x) - 1;
    if (!mp.count(vect[i])) mp[vect[i]] = ++sz;
  }
  build(22, 22, 0);
  for (auto [f, s] : mp) num[s] = f;
  make();
  sz = 0;
  for (auto [F, s] : mp) {
    if (!cunt.count(f(s))) cunt[f(s)] = ++sz;
    fuck[cunt[f(s)]].push_back(s);
  }
  for (int i = 1; i <= 803; i++) spfa(i);
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int ans = 20;
    int kire = mp[vect[a]], khar = mp[vect[b]];
    for (int i = 1; i <= 803; i++)
      ans = min(ans, dist[i][kire] + dist[i][khar]);
    cout << ans << '\n';
  }
  return (0);
}