#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long n, a[10000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 2 || a[i] == 3) {
      cout << a[i] << endl;
    } else if (a[i] == 5 || a[i] == 7) {
      cout << a[i] << endl;
    } else if (a[i] % 2 != 0 && a[i] % 3 != 0) {
      if (a[i] % 5 != 0 && a[i] % 7 != 0) {
        cout << a[i] << endl;
      }
    }
  }
}
