#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<int, int> > v;
  for (int i = 3; i <= 360; i++) {
    for (int j = 1; j <= i - 2; j++) {
      if (j * 180 % i) continue;
      v.push_back({i, j * 180 / i});
    }
  }
  sort(v.begin(), v.end());
  int t;
  cin >> t;
  while (t--) {
    int ang;
    cin >> ang;
    long long ans = -1;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].second == ang) {
        ans = v[i].first;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
