#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int ang, k = 0;
    cin >> ang;
    long long int i = 1;
    while (i < 1000000000) {
      if ((180 * i) % ang == 0) {
        int p = (180 * i) / ang;
        if ((p - i >= 2)) {
          k = 1;
          cout << (i * 180) / ang << endl;
          break;
        }
      }
      i++;
    }
    if (k == 0) {
      cout << "-1" << endl;
    }
  }
}
