#include <bits/stdc++.h>
using namespace std;
void solve(int ang) {
  int x, n;
  x = 360;
  n = 2 * ang;
  for (int i = 2; i <= 360; i++) {
    while (x % i == 0 && n % i == 0) {
      x /= i;
      n /= i;
    }
  }
  if (ang <= 179) {
    int n1 = n;
    int x1 = x;
    while (x < n + 2) {
      x += x1;
      n += n1;
    }
    cout << x << '\n';
  } else
    cout << -1 << '\n';
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int ang;
    cin >> ang;
    solve(ang);
  }
}
