#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  vector<double> vv;
  vv.push_back(0);
  for (double i = 1; i <= 400; i++) {
    vv.push_back(180 / i);
  }
  cin >> t;
  while (t--) {
    double n;
    cin >> n;
    bool is = 0;
    for (int i = 3; i < vv.size(); i++) {
      double x = 0;
      bool don = 0;
      for (int j = 0; j < i - 2; j++) {
        x += vv[i];
        if (x == n) {
          cout << i << endl;
          don = 1;
          break;
        }
      }
      if (don) {
        is = 1;
        break;
      }
    }
    if (!is) cout << -1 << endl;
  }
  return 0;
}
