#include <bits/stdc++.h>
using namespace std;
int n;
int input[1000001];
int complement(int num) { return 8388607 ^ num; }
int bitpow[26];
int dp[1 << 23];
int arr[1 << 23];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    arr[a]++;
    input[i] = a;
  }
  bitpow[0] = 1;
  for (int i = 1; i <= 25; i++) bitpow[i] = 2 * bitpow[i - 1];
  for (int i = 0; i < bitpow[22 + 1]; i++)
    if (arr[i])
      dp[i] = i;
    else
      dp[i] = -1;
  for (int i = 0; i <= 22; i++)
    for (int j = 0; j <= 8388607; j++) {
      if (j & bitpow[i]) {
        if (dp[j ^ bitpow[i]] != -1) dp[j] = dp[j ^ bitpow[i]];
      }
    }
  for (int i = 1; i <= n; i++) printf("%d ", dp[complement(input[i])]);
}
