#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, z, cnt, sum, num, ans;
int a[1000005], dp[4200000];
const int mod = (1 << 22) - 1;
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!('0' <= c && c <= '9')) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (('0' <= c && c <= '9')) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int main() {
  memset(dp, -1, sizeof(dp));
  n = read();
  for (int i = 1; i <= n; i++) {
    a[i] = read();
    dp[(~a[i]) & mod] = a[i];
  }
  for (int i = mod; i; i--)
    if (!~dp[i])
      for (int j = 1; j <= mod; j <<= 1)
        if (~dp[i | j]) {
          dp[i] = dp[i | j];
          break;
        }
  for (int i = 1; i <= n; i++) printf("%d\n", dp[a[i]]);
  return 0;
}
