#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int inf = 1000000000;
const double eps = 0.0000001;
int memo[30];
void calc_memo() {
  fill(begin(memo), end(memo), 1);
  for (int i = 0b11; i <= (1 << 25) - 1; i = (i << 1) | 1) {
    int m = (int)log2(i + 1);
    for (int b = 2; b * b < i; b++) {
      if (i % b == 0) {
        memo[m] = i / b;
        break;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> q;
  calc_memo();
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    if ((a & (a + 1)) != 0) {
      int mask = 1;
      int res = 0;
      while (mask <= a) {
        res |= mask;
        mask <<= 1;
      }
      cout << res << "\n";
    } else {
      int z = (int)log2(a + 1);
      cout << memo[z] << "\n";
    }
  }
  return 0;
}
