#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const double eps = 1e-9;
const int N = 2e5 + 5;
int ans;
long long ch, ca, cr, cd;
string s;
vector<long long> cost;
vector<int> folar;
long long solve() {
  int T;
  cin >> T;
  while (T--) {
    bool gago = false;
    double ang;
    cin >> ang;
    double x = (double)180 / ang;
    int l = 2, r = 0;
    while ((x - floor(x)) >= 0.000001) {
      r++;
      x /= (double)r;
      x *= (double)l;
      l++;
      if (l >= 100000) {
        folar.push_back(-1);
        gago = true;
        break;
      }
    }
    if (gago) continue;
    double fu = 180 - ang;
    double y = x;
    while (fu <= 180 / x) x += y;
    y = x;
    while (x < 3) x += y;
    folar.push_back(x);
  }
  for (auto n : folar) cout << n << endl;
  return 0;
}
int main() {
  solve();
  return 0;
}
