#include <bits/stdc++.h>
using namespace std;
bool fun(int k, double n) {
  double t = 180.0 / k;
  for (double i = t; i <= t * (k - 2); i += t) {
    if (fabs(i - n) < 0.000001) return true;
  }
  return false;
}
int main() {
  int t;
  double n;
  cin >> t;
  while (t--) {
    cin >> n;
    int flag = 0;
    for (int i = 3; i <= 998244353; i++) {
      if (fun(i, n)) {
        printf("%d\n", i);
        flag = 1;
        break;
      }
    }
    if (!flag) printf("-1\n");
  }
}
