#include <bits/stdc++.h>
using namespace std;
const int K = 22;
int Dp[(1 << K)], N, V[1000005];
int main() {
  memset(Dp, -1, sizeof(Dp));
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> V[i];
    Dp[V[i]] = V[i];
  }
  for (int i = 0; i < K; i++)
    for (int mask = 0; mask < (1 << K); mask++)
      if ((mask & (1 << i)) != 0 && Dp[mask ^ (1 << i)] != -1)
        Dp[mask] = Dp[mask ^ (1 << i)];
  for (int i = 1; i <= N; i++) cout << Dp[((1 << K) - 1) ^ V[i]] << " ";
  return 0;
}
