#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
const int N = 1e6 + 7;
int ans[1000];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  for (int i = 3; i <= 500; ++i) {
    int num = i - 2;
    for (int j = 1; j <= num; ++j) {
      if ((180 * j) % i == 0) {
        int deg = (180 * j) / i;
        if (deg > 180) continue;
        if (ans[deg]) continue;
        if (ans[deg] == 0) ans[deg] = i;
        ans[deg] = min(ans[deg], i);
      }
    }
  }
  while (t--) {
    int ang;
    cin >> ang;
    if (ans[ang])
      cout << ans[ang] << "\n";
    else {
      if (360 % (180 - ang) == 0) {
        cout << 360 / (180 - ang) << "\n";
      } else
        cout << -1 << "\n";
    }
  }
  return 0;
}
