#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int p = 0; p < t; p++) {
    int ang;
    cin >> ang;
    if (ang == 179) {
      cout << 360 << endl;
      continue;
    }
    int n = 3;
    int ans = -1;
    while (true) {
      if ((ang * n) % 180 == 0 && (((n - 2) * 180) / n >= ang)) {
        ans = n;
        break;
      }
      n++;
      if (n > 180) break;
    }
    cout << ans << endl;
  }
  return 0;
}
