#include <bits/stdc++.h>
using namespace std;
int T, ang;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> T;
  while (T > 0) {
    --T;
    cin >> ang;
    int rs = -1;
    for (int n = 3; n <= 100000; ++n) {
      int x = (n - 2) * 180, y = n * ang;
      if (x < y) continue;
      int k = gcd(x, y);
      x = x / k;
      y = y / k;
      if ((n - 2) % x == 0) {
        rs = n;
        break;
      }
    }
    cout << rs << '\n';
  }
}
