#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6 + 7;
long long dp[(1 << 23)];
long long a[MAXN];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    dp[a[i]] = a[i];
  }
  for (long long i = 0; i < 23; ++i) {
    for (long long mask = 0; mask < (1 << 23); ++mask) {
      if (mask & (1 << i)) {
        if (dp[mask] > 0) continue;
        if (dp[mask ^ (1 << i)] > 0) {
          dp[mask] = dp[mask ^ (1 << i)];
          continue;
        }
      }
    }
  }
  for (long long i = 1; i <= n; ++i) {
    long long x = ((1 << 23) - 1) ^ a[i];
    cout << dp[x] << " ";
  }
}
