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>
namespace nim {
using u64 = uint64_t;
template <int k, typename Out>
struct Reducer {
  static_assert(k <= 6, "");
  u64 multiply(u64 a, u64 b) const {
    static const u64 P = 1ULL << (1 << k - 1);
    u64 a1 = a / P, a0 = a % P, b1 = b / P, b0 = b % P,
        c = out.multiply(a0, b0);
    return out.multiply(out.multiply(a1, b1), P / 2) ^
           (out.multiply(a0 ^ a1, b0 ^ b1) ^ c) * P ^ c;
  }

 private:
  Out out;
};
template <int k>
struct QuadraticMemorizedNim {
  static_assert(k <= 3, "");
  static const int N = 1 << (1 << k);
  QuadraticMemorizedNim() : table() {
    static Reducer<k, QuadraticMemorizedNim<k - 1>> out;
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        table[i][j] = out.multiply(i, j);
      }
    }
  }
  u64 multiply(u64 a, u64 b) const { return table[a][b]; }
  u64 table[N][N];
};
template <>
struct QuadraticMemorizedNim<0> {
  static const int N = 2;
  QuadraticMemorizedNim() {}
  u64 multiply(u64 a, u64 b) const { return a && b; }
};
template <u64 G>
struct LinearMemorizedNim {
  static const int N = 1 << 16;
  LinearMemorizedNim() : exp(), log() {
    static Reducer<4, Reducer<3, QuadraticMemorizedNim<3>>> reduced;
    log[exp[0] = 1] = 0;
    for (int i = 1; i < N - 1; ++i) {
      log[exp[i] = reduced.multiply(exp[i - 1], G)] = i;
    }
  }
  u64 multiply(u64 a, u64 b) const {
    assert(a < N && b < N);
    return a == 0 || b == 0 ? 0 : exp[(log[a] + log[b]) % (N - 1)];
  }

 private:
  int exp[N], log[N];
};
u64 multiply(u64 a, u64 b) {
  static Reducer<6, Reducer<5, Reducer<4, LinearMemorizedNim<258>>>> reduced;
  return reduced.multiply(a, b);
}
}  // namespace nim
using u64 = uint64_t;
u64 power(u64 a, u64 n) {
  u64 result = 1;
  while (n) {
    if (n & 1) {
      result = nim::multiply(result, a);
    }
    a = nim::multiply(a, a);
    n >>= 1;
  }
  return result;
}
const int N = 7;
const u64 M = -1;
const u64 FACTORS[N]{3, 5, 17, 257, 641, 65537, 6700417};
const u64 CRTS[] = {
    12297829382473034410ULL, 7378697629483820646ULL,  1085102592571150095ULL,
    2296870857426870240ULL,  16979062407938588850ULL, 4611615650756935680ULL,
    10691053700478254925ULL,
};
int solve(int k, u64 a, u64 b) {
  std::map<u64, int> map;
  int sqrt = 0;
  while (sqrt * sqrt < FACTORS[k]) {
    map[b = nim::multiply(b, a)] = ++sqrt;
  }
  a = power(a, sqrt), b = 1;
  for (int i = 1; i <= sqrt; ++i) {
    b = nim::multiply(b, a);
    if (map.count(b)) {
      return (i * sqrt - map[b]) % FACTORS[k];
    }
  }
  return -1;
}
int main() {
  int T;
  std::cin >> T;
  while (T--) {
    u64 a, b;
    std::cin >> a >> b;
    bool ok = true;
    u64 result = 0;
#pragma GCC unroll 7
    for (int k = 0; k < N && ok; ++k) {
      u64 m = M / FACTORS[k];
      int e = solve(k, power(a, m), power(b, m));
      if (~e) {
        while (e--) {
          result += result >= M - CRTS[k] ? CRTS[k] + 1 : CRTS[k];
        }
      } else {
        ok = false;
      }
    }
    if (ok) {
      std::cout << result << std::endl;
    } else {
      std::cout << -1 << std::endl;
    }
  }
}