#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
const long long N = 2e5 + 7;
const long long inf = 8e18 + 7;
const int mod = 998244353;
int t, ang;
int main() {
  cin >> t;
  while (t--) {
    cin >> ang;
    if (ang == 179) {
      cout << "360\n";
      continue;
    }
    long long ans = inf;
    for (int k = 1; k <= ang; k++) {
      int n = 180 * k / ang;
      if (n * ang < 180 * k) continue;
      if (n * ang > (n - 2) * 180) continue;
      ans = min(ans, (long long)n);
    }
    cout << (ans == inf ? -1 : ans) << "\n";
  }
  return 0;
}
