#include <bits/stdc++.h>
const int N = (1 << 22);
using namespace std;
int a[N], dp[N];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < (n); i++) scanf("%d", &a[i]), dp[a[i]] = a[i];
  int yek = (1 << 22) - 1;
  for (int i = 0; i < (N); i++)
    for (int j = 0; j < (22); j++)
      if ((i & (1 << j)) && dp[i - (1 << j)]) dp[i] = dp[i - (1 << j)];
  for (int i = 0; i < (n); i++)
    printf("%d ", (dp[yek ^ a[i]] ? dp[yek ^ a[i]] : -1));
}
