#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int gc() {
  static char buf[1 << 16];
  static int ps = 0, sz = 0;
  if (ps == sz) {
    ps = 0;
    sz = fread(buf, 1, 1 << 16, stdin);
  }
  return buf[ps++];
}
inline int ni() {
  char c = gc();
  for (; c == ' ' || c == '\n';) c = gc();
  int o = 0;
  for (; c != ' ' && c != '\n'; c = gc()) o = o * 10 + c - '0';
  return o;
}
void putChar(int c) {
  static char buf[1 << 16];
  static int pos = 0;
  if (c == EOF || pos == 1 << 16) {
    fwrite(buf, sizeof(buf[0]), pos, stdout);
    pos = 0;
  }
  if (c == EOF) return;
  buf[pos++] = c;
}
void printInt(int val) {
  char buf[12];
  int pos = 0, sign = val < 0 ? -1 : 1;
  val = abs(val);
  if (val == 0) buf[pos++] = 48;
  for (; val; val /= 10) buf[pos++] = 48 + val % 10;
  if (sign == -1) buf[pos++] = '-';
  buf[pos] = ' ';
  for (; pos >= 0;) putChar(buf[pos--]);
}
const int G = 1 << 20;
int a, m[G], k;
bitset<G * 4> dp;
inline int GN(int mask) {
  int w = k - 1;
  for (; w > 0; w--) {
    if (mask & (1 << w) && dp[mask ^ (1 << w)]) {
      mask ^= 1 << w;
    }
  }
  return mask & 1 && dp[mask - 1] ? mask - 1 : mask;
}
int main() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
  cout.sync_with_stdio(0);
  ;
  a = ni();
  for (int q = 0; q < a; q++) {
    m[q] = ni();
    dp[m[q]] = 1;
  }
  k = 22;
  for (int w = 0; w < k; w++) {
    int step = 1 << w, mask = step;
    for (; mask < G * 4; mask += step) {
      for (int q = 0; q < step; q++, mask++) {
        if (!dp[mask]) dp[mask] = dp[mask ^ (1 << w)];
      }
    }
  }
  int all = G * 4 - 1, inv;
  for (int q = 0; q < a; q++) {
    inv = all ^ m[q];
    if (!dp[inv])
      printInt(-1);
    else {
      printInt(GN(inv));
    }
  }
  putChar(EOF);
}
