#include <bits/stdc++.h>
using namespace std;
void work(long long ang) {
  for (long long n = 3;; n++) {
    if (ang * n % 180 == 0) {
      if (ang * n / 180 <= n - 2) {
        printf("%I64d\n", n);
        return;
      }
    }
    if (n == 998244353) break;
  }
}
int main() {
  int T;
  int n;
  scanf("%d", &T);
  for (; T--;) {
    scanf("%d", &n);
    work(n);
  }
  return 0;
}
