#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 22;
int n;
bool arr[N];
int invert(int n) {
  int x = 21;
  int m = 1 << 21;
  m = m | (m - 1);
  return n ^ m;
}
int dp[1 << 22];
void solve() {
  int n;
  cin >> n;
  vector<int> input;
  memset(arr, false, sizeof(arr));
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    input.push_back(a);
    arr[a] = true;
  }
  for (int mask = 0; mask < 1 << 22; mask++) {
    if (arr[mask])
      dp[mask] = mask;
    else {
      dp[mask] = 0;
    }
    for (int j = 1; j < 23; j++) {
      if (dp[mask]) {
        break;
      }
      if (mask & 1 << (j - 1)) {
        dp[mask] = dp[mask ^ 1 << (j - 1)];
      }
    }
  }
  for (int a : input) {
    a = invert(a);
    if (dp[a] == 0) {
      cout << -1 << " ";
    } else {
      cout << dp[a] << " ";
    }
  }
  cout << endl;
}
int main() {
  solve();
  return 0;
}
