#include <bits/stdc++.h>
using namespace std;
set<int> q;
const int maxn = 360;
int main() {
  int t, n;
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    int num = 360 / (180 - n);
    int ans = 0;
    if (num * (180 - n) != 360) num++;
    for (int i = num; i <= 360; i++) {
      if ((n * i) % 180 != 0) continue;
      ans = i;
      if (ans != 0) break;
    }
    if (ans == 0)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
