#include <bits/stdc++.h>
using namespace std;
int ans[185];
vector<int> q[185];
int main() {
  for (int i = 1; i < 180; i++) {
    ans[i] = -1;
  }
  for (int i = 3; i <= 180; i++) {
    for (int j = 1; j <= i - 2; j++) {
      if ((180 * j) % i == 0) {
        q[i].push_back((j * 180) / i);
      }
    }
  }
  for (int i = 3; i <= 180; i++) {
    for (int j = 0; j < q[i].size(); j++) {
      if (ans[q[i][j]] == -1) {
        ans[q[i][j]] = i;
      }
    }
  }
  ans[179] = 360;
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    printf("%d\n", ans[n]);
  }
  return 0;
}
