#include <bits/stdc++.h>
using namespace std;
void handler(int a) {
  for (long int n = 3; n <= 998244353; n++) {
    float current = a * n / 180.;
    if (current == round(current)) {
      if (180 / n + a < 180) {
        cout << n << endl;
        return;
      }
    }
  }
  cout << -1 << endl;
}
int main() {
  int n = 0;
  cin >> n;
  int* input = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> input[i];
  }
  for (int i = 0; i < n; i++) {
    handler(input[i]);
  }
  return 0;
}
