#include <bits/stdc++.h>
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  int t, ang, n, k;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &ang);
    n = 180 / gcd(180, ang);
    k = ang / gcd(180, ang);
    if (k == n - 1)
      printf("%d\n", 2 * n);
    else
      printf("%d\n", n);
  }
  return 0;
}
