#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  while (n--) {
    int angle;
    cin >> angle;
    int minVal = -1, mink;
    for (int m = 3; m <= 360; ++m) {
      for (int k = 1; k <= m - 2; ++k) {
        if (angle * m == 180 * k) {
          mink = k;
          minVal = m;
          break;
        }
      }
      if (minVal > 0) break;
    }
    cout << minVal << endl;
  }
  return 0;
}
