#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int iinf = INT_MAX;
const long long linf = 2e18;
const int MOD = 1000000007;
void print(int x) {
  cout << x << endl;
  exit(0);
}
void PRINT(string x) {
  cout << x << endl;
  exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
int T, n;
signed main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    int ans = -1;
    for (int i = 3; i <= 2333; i++)
      if (n * i % 180 == 0 && n <= 180 - 360 / (double)i) {
        ans = i;
        break;
      }
    printf("%d\n", ans);
  }
}
