#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, k, l, m, n;
  cin >> n;
  vector<int> arr(n + 1);
  int t = (1 << 22);
  vector<int> dp(t, -1);
  for (i = 0; i < t; i++) dp[i] = -1;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
    dp[arr[i]] = arr[i];
  }
  for (j = 1; j <= 22; j++) {
    vector<int> temp(t, -1);
    for (i = 0; i < t; i++) {
      if (i & (1 << (j - 1))) {
        temp[i] = dp[i];
        int x1 = (1 << (j - 1));
        int newt = i ^ x1;
        if (dp[newt] > 0) {
          if (temp[i] == -1) temp[i] = dp[newt];
        }
      } else
        temp[i] = dp[i];
    }
    for (i = 0; i < t; i++) dp[i] = temp[i];
  }
  for (i = 1; i <= n; i++) {
    int N = t - 1;
    int n2 = arr[i];
    int x = N ^ n2;
    int a1 = dp[x];
    cout << a1 << " ";
  }
  cout << "\n";
  return 0;
}
