You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).

Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. 

The only line of the test case contains one integer n (1 ≤ n ≤ 10^9).

Output

For each test case, print the answer — the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.

Example

Input


7
1
2
3
12
12345
15116544
387420489


Output


0
-1
2
-1
-1
12
36

Note

Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:

  1. Divide by 6 and get 2519424; 
  2. divide by 6 and get 419904; 
  3. divide by 6 and get 69984; 
  4. divide by 6 and get 11664; 
  5. multiply by 2 and get 23328; 
  6. divide by 6 and get 3888; 
  7. divide by 6 and get 648; 
  8. divide by 6 and get 108; 
  9. multiply by 2 and get 216; 
  10. divide by 6 and get 36; 
  11. divide by 6 and get 6; 
  12. divide by 6 and get 1. 
1
999838675

-1

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
vector<long long> prime;
bitset<1000030> vis;
void seive() {
  vis.set();
  vis[0] = false;
  vis[1] = false;
  vis[2] = true;
  prime.push_back(2);
  for (long long i = 3; i <= 1000030; i += 2) {
    if (vis[i] == 1) {
      prime.push_back(i);
      for (long long j = i * i; j <= 1000030; j += i) {
        vis[j] = 0;
      }
    }
  }
}
bool isPrime(long long n) {
  if (n < 2) return false;
  if (n < 4) return true;
  if (!(n & 1)) return false;
  if (n % 3 == 0) return false;
  long long lim = sqrt(n);
  for (long long i = 5; i <= lim; i += 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
map<long long, long long> primeFact(long long n) {
  map<long long, long long> make_pair;
  while (n % 2 == 0) {
    make_pair[2]++;
    n = n / 2;
  }
  for (long long i = 3; i <= sqrt(n); i += 2) {
    while (n % i == 0) {
      make_pair[i]++;
      n = n / i;
    }
  }
  if (n > 2) {
    make_pair[n]++;
  }
  return make_pair;
}
long long binomialCoeff(long long n, long long k) {
  if (k > n) return 0;
  long long C[n + 1][k + 1];
  long long i, j;
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= min(i, k); j++) {
      if (j == 0 || j == i)
        C[i][j] = 1;
      else
        C[i][j] =
            (C[i - 1][j - 1] % (1000000007) + C[i - 1][j] % (1000000007)) %
            (1000000007);
    }
  }
  return C[n][k];
}
long long countDivisors(long long n) {
  long long cnt = 0;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        cnt++;
      else {
        cnt += 2;
      }
    }
  }
  return cnt;
}
void solve() {
  long long n;
  cin >> n;
  long long cn = 0;
  while (n != 1) {
    cn++;
    if (n % 3 != 0) {
      cout << -1 << "\n";
      return;
    }
    if (n % 6 == 0)
      n /= 6;
    else
      n *= 2;
  }
  cout << cn << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
}
