#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int64_t mod = 1e9 + 7;
int64_t mod1 = 1e9 + 5;
int64_t power(int64_t a, int64_t b) {
  if (b == 0)
    return 1;
  else if (b % 2 == 0)
    return power((((a % mod) * (a % mod)) % mod), b / 2) % mod;
  else
    return ((a % mod) * (power((((a % mod) * (a % mod)) % mod), b / 2) % mod)) %
           mod;
}
int64_t m[1ll << 22];
int64_t dp[1ll << 22];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int64_t n;
  cin >> n;
  int64_t a[n];
  for (int64_t i = 0; i < n; ++i) cin >> a[i];
  memset(dp, 0, sizeof(dp));
  int64_t pre[n + 1];
  for (int64_t i = 0; i < n; ++i) {
    int64_t mask = a[i];
    m[mask] = a[i];
    dp[mask] = 1;
  }
  for (int64_t i = 0; i < 22; ++i) {
    for (int64_t j = 0; j < (1ll << 22); ++j) {
      if (j & (1ll << i)) {
        if (dp[j]) {
          continue;
        } else {
          if (!dp[j ^ (1ll << i)]) continue;
          dp[j] = dp[j ^ (1ll << i)];
          m[j] = m[j ^ (1ll << i)];
        }
      }
    }
  }
  int64_t p = ((1ll << 22) - 1);
  for (int64_t i = 0; i < n; ++i) {
    if (m[(p) ^ a[i]]) {
      cout << m[(p) ^ a[i]] << " ";
    } else {
      cout << -1 << " ";
    }
  }
}
