#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    int i, j, arr[200] = {0}, t, v;
    float c;
    for (i = 3; i <= 1000; i++) {
      for (j = 1; j <= i - 2; j++) {
        c = (180 / (float)i) * j;
        if (c == (int)c && arr[(int)c] == 0) arr[(int)c] = i;
      }
    }
    cin >> t;
    for (i = 0; i < t; i++) {
      cin >> v;
      if (arr[v] == 0)
        cout << -1 << '\n';
      else
        cout << arr[v] << '\n';
    }
  }
  return 0;
}
