#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mx = (1 << 22);
long long freq[mx + 2];
long long dp[mx + 2];
long long expo_pow(long long x, long long y) {
  if (y == 0) return 1;
  y = y % (mod - 1);
  x %= mod;
  if (y == 0) y = mod - 1;
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y >>= 1;
  }
  return res;
}
void solve() {
  long long n, m;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = i + 1;
  }
  long long mx_mask = (1 << 22) - 1;
  for (long long bit = 0; bit < 22; ++bit) {
    for (long long mask = 0; mask < mx; ++mask) {
      if (mask & (1 << bit)) {
        if (dp[mask] == 0) dp[mask] = dp[mask ^ (1 << bit)];
      }
    }
  }
  long long ans[n];
  for (long long i = 0; i < n; i++) {
    if (dp[mx_mask ^ (a[i])])
      ans[i] = a[dp[mx_mask ^ (a[i])] - 1];
    else
      ans[i] = -1;
  }
  for (long long i = 0; i < n; i++) cout << ans[i] << " ";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  long long i = 1;
  while (test--) {
    solve();
  }
}
