#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, cnt = 0, f = 0;
  cin >> t;
  double a[t], r, q1, q2;
  vector<double> b;
  for (long long int i = 0; i < t; i++) {
    cin >> a[i];
  }
  for (long long int i = 3; i <= 180; i++) {
    r = (double)180 / i;
    b.push_back(r);
    cnt++;
  }
  for (long long int i = 0; i < t; i++) {
    for (long long int j = 0; j < cnt; j++) {
      q1 = (double)a[i] / b[j];
      q2 = (double)180 / b[j];
      if (a[i] != 179) {
        if ((floor(q1) == q1) && ((180 - a[i]) != b[j]) && (q1 <= q2)) {
          cout << q2 << "\n";
          f = 1;
          break;
        }
      } else {
        if (a[i] == 179) {
          cout << 360 << "\n";
          f = 1;
          break;
        } else if (a[i] == 135) {
          cout << 8 << "\n";
          f = 1;
          break;
        }
      }
    }
    if (f == 0) {
      cout << -1 << "\n";
    }
    f = 0;
  }
}
