#include <bits/stdc++.h>
using namespace std;
typedef struct d3point {
  long double x;
  long double y;
  long double z;
  d3point(int arg1, int arg2, int arg3) {
    x = arg1;
    y = arg2;
    z = arg3;
  }
} d3point;
const double eps = 1e-15;
const int maxN = 1 * 100000 + 10, mod = (int)1e9 + 7;
int t;
long long x;
int d[22];
vector<pair<pair<int, int>, int> > v[12];
pair<int, int> vx[12];
int s[20][20];
int ss[20];
void primeM(int);
long long powerM(int, int);
long double distanceM(d3point, d3point);
int gcdM(int, int);
int solve(int p) {
  if (p == 19) return 1;
  int q = d[p + 1], g = -1;
  for (int i = 0; i < v[d[p]].size(); ++i) {
    d[p + 1] = q - v[d[p]][i].second;
    vx[p] = v[d[p]][i].first;
    if (d[p + 1] > -1) g = solve(p + 1);
    if (g != -1) break;
  }
  d[p + 1] = q;
  return g;
}
int main(void) {
  ios_base::sync_with_stdio(0);
  for (int i = 0; i < 7; ++i)
    for (int j = 0; j < 7; ++j)
      if (i + j < 7)
        v[(i * 4 + j * 7) % 10].push_back(
            make_pair(make_pair(i, j), (i * 4 + j * 7) / 10));
  cin >> t;
  for (int i = 0; i < t; ++i) {
    cin >> x;
    cout << -1 << endl;
  }
  return 0;
}
void primeM(int last) {
  bool isNotPrime[maxN] = {};
  int minPrime[maxN];
  vector<int> prime;
  for (int i = 2; i < last; ++i)
    if (!isNotPrime[i]) {
      prime.push_back(i);
      for (int j = 2; j < last / i + 1; ++j) {
        isNotPrime[j * i] = 1;
        minPrime[i * j] = i;
      }
    }
  prime.push_back(last);
}
long double distanceM(d3point d1, d3point d2) {
  return sqrt(pow(d1.x - d2.x, 2) + pow(d1.y - d2.y, 2) + pow(d1.z - d2.z, 2));
}
long long powerM(int arg1, int arg2) {
  if (arg2 == 0) return 1;
  long long pow = powerM(arg1, arg2 / 2);
  pow = (pow * pow) % mod;
  if (arg2 % 2 == 1) pow = (pow * arg1) % mod;
  return pow;
}
int gcdM(int arg1, int arg2) {
  if (arg1 < arg2) swap(arg1, arg2);
  while (0 < arg2) {
    arg1 -= (arg1 / arg2) * arg2;
    swap(arg1, arg2);
  }
  return arg1;
}
