#include <bits/stdc++.h>
using namespace std;
const int MAX = 8388608;
const int N = 23;
int power[31] = {0};
int dp[MAX + 1] = {false};
int is[MAX + 1] = {false};
int arr[MAX + 1];
void solve() {
  int n;
  cin >> n;
  for (int j = 1; j <= n; j++) {
    cin >> arr[j];
    is[arr[j]] = arr[j];
  }
  for (int mask = 0; mask <= power[N]; mask++) {
    if (mask & power[0]) {
      dp[mask] = max(dp[mask ^ power[0]], is[mask]);
    } else {
      dp[mask] = max(dp[mask], is[mask]);
    }
    for (int i = 1; i <= N; i++) {
      if (mask & power[i]) {
        dp[mask] = max(dp[mask ^ power[i]], dp[mask]);
      } else {
        dp[mask] = max(dp[mask], dp[mask]);
      }
    }
  }
  for (int j = 1; j <= n; j++) {
    if (dp[(power[N] - 1) ^ arr[j]]) {
      cout << dp[(power[N] - 1) ^ arr[j]] << " ";
    } else {
      cout << -1 << " ";
    }
  }
  cout << "\n";
  return;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  power[0] = 1;
  for (int j = 1; j <= 30; j++) power[j] = power[j - 1] * 2;
  while (t--) {
    solve();
  }
  return 0;
}
