#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int p[200][8];
int main() {
  v.push_back(2);
  v.push_back(3);
  v.push_back(5);
  v.push_back(7);
  v.push_back(11);
  v.push_back(13);
  int t;
  cin >> t;
  for (int i = 1; i <= 180; i++) {
    for (int j = 0; j < v.size(); j++) {
      int y = i;
      while (y % v[j] == 0) {
        p[i][j]++;
        y /= v[j];
      }
    }
  }
  for (int i = 1; i <= t; i++) {
    int ang;
    cin >> ang;
    int x = 1, y = 1;
    for (int i = 0; i < 6; i++) {
      if (p[ang][i] > p[180][i]) {
        y *= (pow(v[i], p[ang][i] - p[180][i]));
      } else {
        x *= (pow(v[i], p[180][i] - p[ang][i]));
      }
    }
    if (x <= y + 1) {
      while (x <= y + 1) {
        x *= 2;
        y *= 2;
      }
    }
    if ((180 * (x - 2) / x) < ang) {
      while ((180 * (x - 2) / x) < ang) {
        x *= 2;
      }
    }
    cout << x << endl;
  }
}
