#include <bits/stdc++.h>
using namespace std;
long long moveX[] = {-1, 0, 1, 0};
long long moveY[] = {0, 1, 0, -1};
long long dp[1 << 22];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long i, n, m, j, t, s, k, p, x, y, ans, prv, nxt, l, r, cnt, cur;
  cin >> n;
  for (i = 0; i < (1 << 22); i++) {
    dp[i] = -1;
  }
  vector<long long> arr(n);
  for (i = 0; i < n; ++i) {
    cin >> arr[i];
    dp[arr[i]] = arr[i];
  }
  for (i = 0; i < (1 << 22); i++) {
    if (dp[i] == -1) continue;
    for (j = 0; j < 22; j++) {
      if (dp[i | (1 << j)] == -1) dp[i | (1 << j)] = dp[i];
    }
  }
  for (i = 0; i < n; i++) {
    long long rev = arr[i] ^ ((1 << 22) - 1);
    cout << dp[rev] << " \n"[i == n - 1];
  }
  return 0;
}
