#include <bits/stdc++.h>
int LSOne(int a) { return a & -a; }
bool isPower2(int a) { return (a & -a) == a; }
int big(int a) {
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) return a / i;
  }
  return 1;
}
int f(int a) {
  if (isPower2(a + 1)) return big(a);
  a++;
  while (!isPower2(a)) a ^= LSOne(a);
  return 2 * a - 1;
}
int main(int argc, char **argv) {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    printf("%d\n", f(a));
  }
  return 0;
}
