Problem: In modern cryptography much is tied to the algorithmic complexity of solving several problems. One of such problems is a discrete logarithm problem. It is formulated as follows: 

Let's fix a [finite field](https://en.wikipedia.org/wiki/Finite_field) and two it's elements a and b. One need to fun such x that a^x = b or detect there is no such x. 

It is most likely that modern mankind cannot solve the problem of discrete logarithm for a sufficiently large field size. For example, for a field of residues modulo prime number, primes of 1024 or 2048 bits are considered to be safe. However, calculations with such large numbers can place a significant load on servers that perform cryptographic operations. For this reason, instead of a simple module residue field, more complex fields are often used. For such field no fast algorithms that use a field structure are known, smaller fields can be used and operations can be properly optimized. 

Developer Nikolai does not trust the generally accepted methods, so he wants to invent his own. Recently, he read about a very strange field — [nimbers](https://en.wikipedia.org/wiki/Nimber), and thinks it's a great fit for the purpose. 

The field of nimbers is defined on a set of integers from 0 to 2^{2^k} - 1 for some positive integer k . Bitwise exclusive or (⊕) operation is used as addition. One of ways to define multiplication operation (⊙) is following properties: 

  * 0 ⊙ a = a ⊙ 0 = 0 
  * 1 ⊙ a = a ⊙ 1 = a 
  * a ⊙ b = b ⊙ a 
  * a ⊙ (b ⊙ c)= (a ⊙ b) ⊙ c 
  * a ⊙ (b ⊕ c) = (a ⊙ b) ⊕ (a ⊙ c) 
  * If a = 2^{2^n} for some integer n > 0, and b < a, then a ⊙ b = a ⋅ b. 
  * If a = 2^{2^n} for some integer n > 0, then a ⊙ a = 3/2⋅ a. 



For example: 

  *  4 ⊙ 4 = 6 
  *  8 ⊙ 8 = 4 ⊙ 2 ⊙ 4 ⊙ 2 = 4 ⊙ 4 ⊙ 2 ⊙ 2 = 6 ⊙ 3 = (4 ⊕ 2) ⊙ 3 = (4 ⊙ 3) ⊕ (2 ⊙ (2 ⊕ 1)) = (4 ⊙ 3) ⊕ (2 ⊙ 2) ⊕ (2 ⊙ 1) = 12 ⊕ 3 ⊕ 2 = 13. 
  * 32 ⊙ 64 = (16 ⊙ 2) ⊙ (16 ⊙ 4) = (16 ⊙ 16) ⊙ (2 ⊙ 4) = 24 ⊙ 8 = (16 ⊕ 8) ⊙ 8 = (16 ⊙ 8) ⊕ (8 ⊙ 8) = 128 ⊕ 13 = 141 
  * 5 ⊙ 6 = (4 ⊕ 1) ⊙ (4 ⊕ 2) = (4⊙ 4) ⊕ (4 ⊙ 2) ⊕ (4 ⊙ 1) ⊕ (1 ⊙ 2) = 6 ⊕ 8 ⊕ 4 ⊕ 2 = 8 



Formally, this algorithm can be described by following pseudo-code. 
    
    
    multiply(a, b) {  
       ans = 0  
       for p1 in bits(a)       // numbers of bits of a equal to one  
           for p2 in bits(b)   // numbers of bits of b equal to one  
              ans = ans xor multiply_powers_of_2(1 << p1, 1 << p2)  
       return ans;  
    }  
    multiply_powers_of_2(a, b) {  
        if (a == 1 or b == 1) return a * b  
        n = maximal value, such 2^{2^{n}} <= max(a, b)  
        power = 2^{2^{n}};  
        if (a >= power and b >= power) {  
            return multiply(power * 3 / 2, multiply_powers_of_2(a / power, b / power))  
        } else if (a >= power) {  
            return multiply_powers_of_2(a / power, b) * power  
        } else {  
            return multiply_powers_of_2(a, b / power) * power  
        }  
    }  
    

It can be shown, that this operations really forms a field. Moreover, than can make sense as game theory operations, but that's not related to problem much. With the help of appropriate caching and grouping of operations, it is possible to calculate the product quickly enough, which is important to improve speed of the cryptoalgorithm. More formal definitions as well as additional properties can be clarified in the wikipedia article at [link](https://en.wikipedia.org/wiki/Nimber). The authors of the task hope that the properties listed in the statement should be enough for the solution. 

Powering for such muliplication is defined in same way, formally a^{⊙ k} = \underbrace{a ⊙ a ⊙ ⋅⋅⋅ ⊙ a}_{k~times}.

You need to analyze the proposed scheme strength. For pairs of numbers a and b you need to find such x, that a^{⊙ x} = b, or determine that it doesn't exist. 

Input

In the first line of input there is single integer t (1 ≤ t ≤ 100) — number of pairs, for which you need to find the discrete logarithm.

In each of next t line there is a pair of integers a b (1 ≤ a, b < 2^{64}). 

Output

For each pair you should print one integer x (0 ≤ x < 2^{64}), such that a^{⊙ x} = b, or -1 if no such x exists. It can be shown, that if any such x exists, there is one inside given bounds. If there are several good values, you can output any of them. 

Example

Input


7
2 2
1 1
2 3
8 10
8 2
321321321321 2
123214213213 4356903202345442785


Output


1
1
2
4
-1
6148914691236517205
68943624821423112

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize(3, "inline", "Ofast")
using namespace std;
int pr[] = {3, 5, 17, 257, 641, 65537, 6700417};
unsigned long long mul[64][64], x, y, f[7], tb[256][256];
int fxk[233];
unordered_map<unsigned long long, int> F;
void exgcd(unsigned long long a, unsigned long long b, unsigned long long &x,
           unsigned long long &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a % b, y, x);
  y -= a / b * x;
}
unsigned long long calc(unsigned long long, unsigned long long);
unsigned long long smul(unsigned long long x, unsigned long long y) {
  unsigned long long ans = 0;
  for (; x; x -= x & (-x))
    for (unsigned long long z = y; z; z -= z & (-z))
      ans ^= calc(x & (-x), z & (-z));
  return ans;
}
unsigned long long calc(unsigned long long x, unsigned long long y) {
  if (x == 1 || y == 1) return x * y;
  if (x < y) swap(x, y);
  int n = fxk[F[x]];
  unsigned long long pw = 1ull << (1 << n);
  if (x >= pw && y >= pw) return smul(pw ^ (pw >> 1), calc(x / pw, y / pw));
  return calc(x / pw, y) * pw;
}
unsigned long long Mul(int x, unsigned long long y, int D = 63) {
  unsigned long long ans = 0;
  for (int j = (0); j <= (D); ++j)
    if (y & (1ull << j)) ans ^= mul[x][j];
  return ans;
}
unsigned long long kar(unsigned long long x, unsigned long long y, int k) {
  if (k <= 2) return tb[x][y];
  int w = 1 << k;
  unsigned long long a1 = x >> w, b1 = y >> w, a2 = x & ((1ull << w) - 1),
                     b2 = y & ((1ull << w) - 1);
  unsigned long long p = kar(a1, b1, k - 1), q = kar(a2, b2, k - 1),
                     r = kar(a1 ^ a2, b1 ^ b2, k - 1);
  return ((q ^ r) << w) ^ Mul(w - 1, p, w - 1) ^ q;
}
unsigned long long qMul(unsigned long long x, unsigned long long y) {
  return kar(x, y, 5);
}
unsigned long long pw(unsigned long long a, unsigned long long b) {
  unsigned long long ans = 1;
  for (; b; b >>= 1, a = qMul(a, a))
    if (b & 1) ans = qMul(ans, a);
  return ans;
}
unordered_map<unsigned long long, int> z;
unsigned long long ans[3], B[2];
void Add(unsigned long long x, unsigned long long y) {
  for (int i = (0); i <= (1); ++i) B[i] = y & ((1ll << 32) - 1), y >>= 32;
  for (int i = (0); i <= (1); ++i) ans[i] += x * B[i];
  for (int i = (0); i <= (1); ++i)
    ans[i + 1] += ans[i] >> 32, ans[i] &= (1ll << 32) - 1;
}
void solve(unsigned long long a, unsigned long long b) {
  unsigned long long c = -1;
  ans[0] = ans[1] = ans[2] = 0;
  for (int i = (0); i <= (6); ++i) {
    z.clear();
    unsigned long long w = pw(a, c / pr[i]), g = 1, bd = pw(b, c / pr[i]);
    int cmz = sqrt(pr[i] + 0.5);
    bool flag = 0;
    for (int j = (0); j <= (cmz - 1); ++j) {
      if (g == bd) {
        flag = 1;
        Add(j, f[i]);
        break;
      }
      if (!z.count(g)) z[g] = j;
      g = qMul(g, w);
    }
    if (flag) continue;
    w = pw(a, c - c / pr[i] * cmz), g = w;
    for (int j = (1); j <= (pr[i] / cmz); ++j) {
      unsigned long long k = qMul(g, bd);
      if (z.count(k)) {
        flag = 1;
        Add(z[k] + j * cmz, f[i]);
        break;
      }
      g = qMul(g, w);
    }
    if (!flag) {
      puts("-1");
      return;
    }
  }
  unsigned long long tt = ans[0] + (ans[1] << 32), p = tt + ans[2];
  printf("%llu\n", p < tt ? p + 1 : p);
}
unsigned long long inv(unsigned long long a, unsigned long long p) {
  unsigned long long x, y;
  exgcd(a, p, x, y);
  return x > p ? x + p : x;
}
int main() {
  int T;
  scanf("%d", &T);
  for (int i = (0); i <= (63); ++i) F[1ull << i] = i;
  for (int i = (2); i <= (63); ++i) fxk[i] = fxk[i >> 1] + 1;
  for (int i = (0); i <= (63); ++i)
    for (int j = (0); j <= (63); ++j) mul[i][j] = calc(1ull << i, 1ull << j);
  for (int i = (0); i <= (255); ++i)
    for (int j = (0); j <= (255); ++j) {
      for (int x = (0); x <= (7); ++x)
        if (i & (1 << x))
          for (int y = (0); y <= (7); ++y)
            if (j & (1 << y)) tb[i][j] ^= mul[x][y];
    }
  unsigned long long c = -1, ff = 0;
  for (int i = (0); i <= (6); ++i)
    f[i] = inv(c / pr[i] % pr[i], pr[i]) * (c / pr[i]);
  while (T--) {
    unsigned long long a, b;
    scanf("%llu%llu", &a, &b);
    solve(a, b);
  }
  return 0;
}