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