#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n;
  while (n--) {
    int m;
    cin >> m;
    if (m == 179) {
      cout << 360 << "\n";
      continue;
    }
    for (int i = 3; i <= 180; i++) {
      long double ugol = 180.0 / i;
      if (round(m / ugol) == m / ugol) {
        if (m / ugol < i - 1) {
          cout << i << "\n";
          break;
        }
      }
    }
  }
}
