#include <bits/stdc++.h>
using namespace std;
int dp[4194305];
int getInv(int a) {
  int it = 1, y = 0;
  for (int j = 0; j < 22; j++) {
    if (!(a & it)) {
      y |= it;
    }
    it <<= 1;
  }
  return y;
}
int ch[1000001];
int main() {
  int k;
  cin >> k;
  int a;
  memset(dp, 255, sizeof dp);
  for (int i = 0; i < k; i++) {
    scanf("%d", &ch[i]);
    dp[ch[i]] = ch[i];
  }
  for (int mask = 0; mask < (1 << 22); mask++) {
    for (int i = 0; i < 22; i++) {
      int it = 1 << i;
      if ((mask & it) && dp[mask ^ it] != -1) {
        dp[mask] = dp[mask ^ it];
      }
    }
  }
  for (int i = 0; i < k; i++) {
    cout << dp[ch[i] ^ ((1 << 22) - 1)] << " ";
  }
  return 0;
}
