#include <bits/stdc++.h>
using namespace std;
long long int u = 4194304;
long long int dp[4194304];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]] = a[i];
  }
  for (long long int i = 0; i < (1 << 22); i++) {
    for (long long int j = 0; j < 22; j++) {
      if (i & (1 << j)) {
        if (dp[i ^ (1 << j)] != 0) {
          dp[i] = dp[i ^ (1 << j)];
        }
      }
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (dp[((1 << 22) - 1) ^ a[i]] != 0) {
      cout << dp[((1 << 22) - 1) ^ a[i]] << " ";
    } else {
      cout << "-1 ";
    }
  }
  return 0;
}
