#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  vector<int> v;
  for (int i = 1; i <= 180; i++) {
    if (180 % i == 0) v.push_back(i);
  }
  int x, f, y;
  double num;
  while (t--) {
    cin >> x;
    f = 0;
    for (int i = 3; i <= 360; i++) {
      num = 180.0 / i;
      y = 1;
      while (num * y < x) {
        y++;
      }
      if (num * y - x < 1e-4 && y <= i - 2) {
        cout << i << endl;
        f = 1;
        break;
      }
    }
    if (!f) cout << -1 << endl;
  }
  return 0;
}
