#include <bits/stdc++.h>
using namespace std;
int getFldsFromLine(char *line, std::vector<char *> &res,
                    const char *sep = " \t\n\v\f\r");
int main(int argc, char **argv) {
  FILE *infile = stdin;
  char *line;
  line = (char *)calloc(1000000, sizeof(char));
  if (line == NULL) {
    fprintf(stderr, "Couldn't allocate space for '%s'\nBye!\n", "line");
    exit(-1);
  };
  std::vector<char *> flds;
  int numFlds, numCases, caseNum = 0;
  int q;
  int64_t n;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int numMoves = 0;
    cin >> n;
    while (n % 2 == 0) {
      numMoves += 1;
      n /= 2;
    }
    while (n % 3 == 0) {
      numMoves += 2;
      n /= 3;
    }
    while (n % 5 == 0) {
      numMoves += 3;
      n /= 5;
    }
    if (n != 1) numMoves = -1;
    cout << numMoves << endl;
  }
  return (0);
}
int getFldsFromLine(char *line, std::vector<char *> &res, const char *sep) {
  res.clear();
  char *tok = strtok(line, sep);
  while (tok) {
    res.push_back(tok);
    tok = strtok(0, sep);
  }
  return res.size();
}
