#include <bits/stdc++.h>
using namespace std;
long long gcd(long long loc, long long b) {
  if (loc == 0LL) return b;
  if (b == 0LL) return loc;
  return gcd(b, loc % b);
}
long long modx(long long Base, long long exponent) {
  long long store = 1;
  if (Base == 1) return Base;
  while (exponent) {
    if (exponent & 1) store = (store * Base) % 1000000007;
    Base = (Base * Base) % 1000000007;
    exponent = exponent >> 1;
  }
  return store;
}
long long inmodx(long long num) { return (modx(num, 1000000007 - 2LL)); }
bool cmp(pair<long long int, long long int> loc,
         pair<long long int, long long int> b) {
  if (loc.second < b.second) return 1;
  if (loc.second > b.second) return 0;
  if (loc.first <= b.first) return 1;
  return 0;
}
long long int inp[500005];
long long int num;
signed main() {
  scanf("%lld", &num);
  for (long long int idx = 0; idx < num; idx++) {
    scanf("%lld", &inp[idx]);
  }
  vector<long long int> store;
  store.clear();
  for (long long int idx = 0; idx < num; idx++) {
    long long int temp = inp[idx];
    long long int tot = 0;
    while (temp != 0) {
      temp = temp >> 1;
      tot *= 2;
      tot++;
    }
    if (inp[idx] != tot) {
      store.push_back(tot);
      continue;
    }
    long long int val = sqrt(inp[idx]);
    long long int flag = 0;
    for (long long int j = 2; j < val + 1; j++) {
      if (inp[idx] % j == 0) {
        tot = inp[idx] / j;
        flag = -1;
      }
      if (flag == -1) break;
    }
    if (inp[idx] == tot) {
      store.push_back(1LL);
    } else {
      store.push_back(tot);
    }
  }
  for (long long int idx = 0; idx < store.size(); idx++) {
    cout << store[idx] << endl;
  }
  return 0;
}
