#include <bits/stdc++.h>
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x;
    scanf("%d", &x);
    int i;
    int g = 0;
    if (x == 179) {
      printf("360\n");
      continue;
    }
    for (i = 3; i <= 180; i++) {
      double r = 180.0 / i;
      int a = x / r;
      if (double(a) == x / r) {
        if (a >= i - 1) {
          printf("%d\n", 2 * i);
        } else
          printf("%d\n", i);
        g = 1;
        break;
      }
    }
    if (g != 1) {
      printf("-1");
    }
  }
}
