#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void mad(long long &a, long long b) {
  a = (a + b) % 1000000007;
  if (a < 0) a += 1000000007;
}
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (!a) return b;
  return gcd(b % a, a);
}
int dp[1 << 22];
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < 1 << 22; i++) dp[i] = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = i;
  }
  for (int i = 0; i < 1 << 22; i++) {
    if (dp[i] == -1) continue;
    for (int j = 0; j < 22; j++) {
      if (!(i & (1 << j))) dp[i | (1 << j)] = dp[i];
    }
  }
  for (int i = 0; i < n; i++) {
    int id = dp[(1 << 22) - 1 - a[i]];
    if (id == -1)
      cout << -1 << " ";
    else
      cout << a[id] << " ";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
}
