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>
using namespace std;
void input_File() {}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i < n; i++)
    if (n % i == 0) return false;
  return true;
}
long long sumofdigits(long long n) {
  long long c = 0;
  while (n > 0) {
    c++;
    n /= 10;
  }
  return c;
}
long long MaxSubArraySumReturn(long long a[], long long n) {
  long long sum = 0, best = 0;
  for (long long i = 0; i < n; i++) {
    sum = max(a[i], a[i] + sum);
    best = max(best, sum);
  }
  return best;
}
long long fact(long long n) {
  long long res = 1;
  for (long long i = 2; i <= n; i++) res = res * i;
  return res;
}
long long nCr(long long n, long long r) {
  return fact(n) / (fact(r) * fact(n - r));
}
bool sortinrev(const pair<long long, long long> &a,
               const pair<long long, long long> &b) {
  return (a.first > b.first);
}
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 = cnt + 2;
    }
  }
  return cnt;
}
long long setBitCount(long long n) {
  long long ans = 0;
  while (n) n &= n - 1, ans++;
  return ans;
}
long long power(long long a, long long b) {
  long long result = 1;
  while (b) {
    if (b & 1) {
      result *= a;
      b--;
    } else {
      a *= a;
      b >>= 1;
    }
  }
  return result;
}
vector<long long> nextLargerElementUsingStack(long long a[], long long n) {
  stack<long long> s;
  vector<long long> ans;
  ans.push_back(-1);
  s.push(a[n - 1]);
  for (long long i = n - 2; i >= 0; i--) {
    if (a[i] > s.top()) {
      while (!s.empty() and a[i] > s.top()) s.pop();
      if (s.empty())
        ans.push_back(-1);
      else
        ans.push_back(s.top());
      s.push(a[i]);
    } else if (a[i] < s.top()) {
      ans.push_back(s.top());
      s.push(a[i]);
    }
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
void solve() {
  long long n;
  cin >> n;
  if (n == 1) {
    cout << 0 << "\n";
    return;
  }
  if (n == 3) {
    cout << 2 << "\n";
    return;
  }
  if (n < 6 or n % 3) {
    cout << -1 << "\n";
    return;
  }
  long long count = 0;
  while (n > 1) {
    if (n <= 1) break;
    if (n % 6 == 0)
      n /= 6, count++;
    else if ((n * 2 % 6) == 0)
      n *= 2, count++;
    else {
      cout << -1 << "\n";
      return;
    }
  }
  cout << count << "\n";
}
signed main() {
  input_File();
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long isTestCasePresent = 1;
  if (isTestCasePresent == 0) {
    long long t = 1;
    while (t--) {
      solve();
    }
  } else {
    long long t;
    cin >> t;
    while (t--) {
      solve();
    }
  }
  return 0;
}
