#include <bits/stdc++.h>
using namespace std;
const long long limita = 998244353;
long long n, v[200], st, dr, mij, mul, ans, maxDegree;
long long GCD(long long x, long long y) {
  if (y != 0)
    return GCD(y, x % y);
  else
    return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (int i = 1; i <= n; i++) {
    ans = 180 / GCD(180LL, v[i]);
    mul = 0;
    st = 1;
    dr = limita / ans;
    while (st <= dr) {
      mij = (st + dr) / 2;
      maxDegree = (mij * ans - 2) * 180 / (mij * ans);
      if (maxDegree >= v[i]) {
        dr = mij - 1;
        mul = mij;
      } else
        st = mij + 1;
    }
    if (mul == 0)
      cout << -1 << '\n';
    else
      cout << mul * ans << '\n';
  }
}
