#include <bits/stdc++.h>
using namespace std;
const int LOG = 22;
int32_t main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> tab(n);
  vector<int> dp(1 << LOG);
  vector<pair<int, int> > samples(1 << LOG, {-1, -1});
  auto update = [&](int a, int i) {
    if (i == -1) return;
    if (samples[a].first != -1) samples[a].second = i;
    samples[a].first = i;
  };
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
    dp[tab[i]]++;
    update(tab[i], i);
  }
  for (int i = 0; i < LOG; i++) {
    for (int m = 0; m < (1 << LOG); m++) {
      if (m & (1 << i)) {
        dp[m] += dp[m ^ (1 << i)];
        update(m, samples[m ^ (1 << i)].first);
        update(m, samples[m ^ (1 << i)].second);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int a = tab[i] ^ ((1 << LOG) - 1);
    if (samples[a].first == i)
      cout << (samples[a].second == -1 ? -1 : tab[samples[a].second]) << " ";
    else
      cout << (samples[a].first == -1 ? -1 : tab[samples[a].first]) << " ";
  }
}
