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(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
using namespace std;
const unsigned long long ORD = (unsigned long long)-1;
const int MAXB = 2600;
template <typename _T>
void read(_T &x) {
  x = 0;
  char s = getchar();
  int f = 1;
  while (s > '9' || s < '0') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + (s - '0'), s = getchar();
  }
  x *= f;
}
template <typename _T>
void write(_T x) {
  if (x < 0) {
    putchar('-');
    x = (~x) + 1;
  }
  if (9 < x) {
    write(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename _T>
_T MAX(const _T a, const _T b) {
  return a > b ? a : b;
}
template <typename _T>
_T MIN(const _T a, const _T b) {
  return a < b ? a : b;
}
unsigned long long fac[10] = {0, 3, 5, 17, 257, 641, 65537, 6700417};
int tot = 7;
bool exists;
unsigned long long nim[256][256];
unsigned long long Mul(unsigned long long x, unsigned long long y,
                       int len = 32) {
  if (x == 0 || y == 0) return 0;
  if (x == 1 || y == 1) return x * y;
  if (len <= 4 && nim[x][y]) return nim[x][y];
  unsigned long long xa = x >> len, xb = x ^ (xa << len), ya = y >> len,
                     yb = y ^ (ya << len);
  unsigned long long a = Mul(xb, yb, len >> 1),
                     b = Mul(xa ^ xb, ya ^ yb, len >> 1),
                     c = Mul(xa, ya, len >> 1),
                     d = Mul(c, 1ull << len - 1, len >> 1);
  unsigned long long re = ((b ^ a) << len) ^ a ^ d;
  if (len <= 4) nim[x][y] = re;
  return re;
}
unsigned long long Qkpow(unsigned long long a, unsigned long long indx) {
  unsigned long long ret = 1;
  while (indx) {
    if (indx & 1) ret = Mul(ret, a);
    a = Mul(a, a), indx >>= 1;
  }
  return ret;
}
unsigned long long Ord(const unsigned long long x) {
  unsigned long long ret = ORD;
  for (int i = (tot); i >= (1); i--)
    if (Qkpow(x, ret / fac[i]) == 1) ret /= fac[i];
  return ret;
}
namespace HashMap {
const int MAXS = 10009;
int head[MAXS], stk[MAXS];
int nxt[MAXB], val[MAXB];
unsigned long long key[MAXB];
int cnt = 0, top = 0;
void Clean() {
  cnt = 0;
  while (top) head[stk[top]] = 0, stk[top--] = 0;
}
void Insert(const unsigned long long nKey, const int nVal) {
  int has = nKey % MAXS;
  for (int i = head[has]; i; i = nxt[i])
    if (key[i] == nKey) return;
  if (!head[has]) stk[++top] = has;
  cnt++;
  val[cnt] = nVal, key[cnt] = nKey;
  nxt[cnt] = head[has], head[has] = cnt;
}
int Find(const unsigned long long nKey) {
  int has = nKey % MAXS;
  for (int i = head[has]; i; i = nxt[i])
    if (key[i] == nKey) return val[i];
  return -1;
}
}  // namespace HashMap
int BSGS(const unsigned long long a, const unsigned long long b, const int lim,
         const unsigned long long ord) {
  using namespace HashMap;
  Clean();
  int B = ceil(sqrt(lim));
  unsigned long long pw = 1;
  for (int i = (0); i <= (B - 1); i++) Insert(pw, i), pw = Mul(pw, a);
  unsigned long long tmp = 1, base = Qkpow(a, ord - B % ord), t;
  for (int i = (0); i <= (B - 1); i++) {
    if (~(t = Find(Mul(tmp, b)))) return t + i * B;
    tmp = Mul(tmp, base);
  }
  return -1;
}
unsigned long long Solve(const int indx, const unsigned long long a,
                         const unsigned long long b,
                         const unsigned long long n) {
  if (a == b) return n == 1 ? 0 : 1;
  if (indx > tot) {
    exists = false;
    return 0;
  }
  if (n % fac[indx]) return Solve(indx + 1, a, b, n);
  unsigned long long p = n / fac[indx], q = fac[indx];
  int v = BSGS(Qkpow(a, p), Qkpow(b, p), q, n);
  if (!(~v)) {
    exists = false;
    return 0;
  }
  return q * Solve(indx + 1, Qkpow(a, q), Mul(b, Qkpow(a, n - v)), p) + v;
}
int main() {
  int T;
  read(T);
  while (T--) {
    unsigned long long a, b;
    read(a), read(b);
    if (a == b) {
      puts("1");
      continue;
    }
    exists = true;
    unsigned long long ans = Solve(1, a, b, Ord(a));
    if (exists)
      write(ans), putchar('\n');
    else
      puts("-1");
  }
  return 0;
}