#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int T, ang;
double a[2000];
int main() {
  cin >> T;
  while (T--) {
    cin >> ang;
    bool flag = true;
    for (int i = 3; i <= 1200; i++) {
      a[i] = 180.0 / i;
      if ((int)(ang / a[i]) * a[i] == ang && (int)(ang / a[i]) <= i - 2) {
        cout << i << endl;
        flag = false;
        break;
      }
    }
    if (flag) cout << -1 << endl;
  }
}
