#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double f;
    cin >> f;
    bool y = false;
    for (double j = 3; j < 998244353; j++) {
      double p = (180 / j);
      double k = p;
      int h = 1;
      while (k < f && h < j - 2) {
        k += p;
        h++;
      }
      if (f == k) {
        cout << j << endl;
        y = true;
        break;
      }
      if (y) {
        cout << "-1" << endl;
        break;
      }
    }
  }
  return 0;
}
