#include <bits/stdc++.h>
using namespace std;
int dp[1 << 22], ar[1000000];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (1 << 22); i++) dp[i] = -1;
  for (int i = 0; i < n; i++) {
    scanf("%d", &ar[i]);
    dp[ar[i]] = ar[i];
  }
  for (int i = 0; i < (1 << 22); i++) {
    if (dp[i] != -1) {
      for (int j = 0; j < 22; j++) {
        dp[i | (1 << j)] = dp[i];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << dp[ar[i] ^ ((1 << 22) - 1)] << " ";
  }
}
