#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e7 + 10;
int dp[maxn], a[maxn];
int main() {
  int n = read();
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    dp[a[i]] = a[i];
  }
  int N = (1 << 22);
  for (int i = 0; i < N; i++) {
    if (dp[i] == -1) {
      for (int j = 0; j < 22; j++) {
        if ((i & (1 << j)) && dp[i ^ (1 << j)] != -1) dp[i] = dp[i ^ (1 << j)];
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%d\n", dp[a[i] ^ (N - 1)]);
  puts("");
  return 0;
}
