#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
const int MAX_N = 400;
int ans[181];
void init() {
  fill(ans, ans + 181, -1);
  for (int i = 3; i <= MAX_N; ++i) {
    double min_deg = 180.0 / i;
    for (int deg = 1; deg <= 180; ++deg) {
      if (ans[deg] != -1) continue;
      if (deg - floor(deg / min_deg + EPS) * min_deg < EPS &&
          deg <= min_deg * double(i - 2))
        ans[deg] = i;
    }
  }
}
int main() {
  init();
  int t, deg;
  cin >> t;
  while (t--) {
    cin >> deg;
    cout << ans[deg] << "\n";
  }
}
