#include <bits/stdc++.h>
int x[30];
template <class T>
inline void read(T &num) {
  num = 0;
  char c = getchar();
  T sign = 1;
  while (c < '0' || c > '9') {
    if (c == '-') sign = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    num = (num << 1) + (num << 3) + (c ^ 48);
    c = getchar();
  }
  num *= sign;
}
int main() {
  int t, a;
  read(t);
  while (t--) {
    read(a);
    int tag = a, cnt = 0, ok = 0, ans = 0;
    while (tag) {
      x[++cnt] = tag & 1;
      if (!x[cnt]) ok = 1;
      tag >>= 1;
    }
    if (ok) {
      for (register int i = cnt; i; --i) {
        ans <<= 1;
        if (!x[i]) ++ans;
      }
      printf("%d\n", ans ^ a);
    } else {
      for (register int i = 2; i * i <= a; ++i)
        if (a % i == 0) {
          printf("%d\n", a / i);
          ok = 1;
          break;
        }
      if (!ok) puts("1");
    }
  }
  return 0;
}
