#include <bits/stdc++.h>
using namespace std;
long long maxInt = 998244353;
int main() {
  int q;
  cin >> q;
  for (int t = 0; t < q; t++) {
    long long angle;
    cin >> angle;
    long long answer = -1;
    for (long long i = 3; i <= maxInt; i++) {
      if ((angle * i) % 180 == 0 && ((180 - angle) * i > 180)) {
        answer = i;
        break;
      }
    }
    cout << answer << "\n";
  }
}
