#include <bits/stdc++.h>
using namespace std;
long long t, ang, res;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> t;
  while (t--) {
    cin >> ang;
    ang *= 2;
    res = -1;
    for (long long i = 3; i <= 360; i++) {
      if ((ang * i) % 360 == 0 && (ang * i / 360) <= i - 2) {
        res = i;
        break;
      }
    }
    cout << res << "\n";
  }
  return 0;
}
