#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double pi = 3.1415926535897932384626;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
long long q, x;
long long q_pow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans *= x;
    y >>= 1;
    x *= x;
  }
  return ans;
}
int main() {
  q = read();
  while (q--) {
    x = read();
    long long ans = 1, cnt = 0, flag = 0;
    while (x) {
      ++cnt;
      if (x % 2 == 0) flag = 1;
      x >>= 1;
    }
    if (flag)
      printf("%lld\n", q_pow(2, cnt) - 1);
    else {
      x = q_pow(2, cnt) - 1;
      for (long long i = 2; i * i <= x; ++i) {
        if (x % i == 0) {
          ans = max(ans, x / i);
          ans = max(ans, i);
        }
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
