#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 22) + 4;
int freq[N];
int dp[N];
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    dp[a[i]] = a[i];
  }
  for (int i = 0; i < 22; i++) {
    for (int msk = 0; msk < (1 << 22); msk++) {
      if (msk & (1 << i)) dp[msk] = max(dp[msk], dp[msk ^ (1 << i)]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cout << dp[a[i] ^ ((1 << 22) - 1)] << '\n';
  }
}
