#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 9;
const long double PI = acosl(-1.0);
const long double EPS = 1e-9;
bool check(int a) {
  for (int i = 0; i < int(26); ++i)
    if (a == (1 << i) - 1) return true;
  return false;
}
bool bit(int n, int i) { return n & (1 << i); }
int func(int a) {
  int cnt = 0;
  int b = a;
  int n = 0;
  while (a > 0) {
    a /= 2;
    cnt++;
  }
  for (int i = 0; i < int(cnt); ++i) {
    if (!bit(b, i)) n += (1 << i);
  }
  return n ^ b;
}
int prime(int a) {
  int ans = 1;
  for (int i = int(2); i < int(int(sqrt(double(a))) + 1); ++i)
    if (a % i == 0) ans = max(ans, max(i, a / i));
  return ans;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < int(n); ++i) {
    int a;
    cin >> a;
    if (check(a))
      cout << prime(a) << endl;
    else
      cout << func(a) << endl;
  }
}
