#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
const int L = 23;
const int MAX = (1 << L);
int n, arr[N], dp[2][MAX + 10];
void upd(int &x, int y) {
  if (y > 0) x = y;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    dp[0][arr[i]] = arr[i];
  }
  for (int j = 1; j < L; j++) {
    for (int mask = 0; mask < MAX; mask++) dp[(j & 1)][mask] = 0;
    for (int mask = 0; mask < MAX; mask++) {
      upd(dp[(j & 1)][mask], dp[(~j & 1)][(mask ^ (1 << (j - 1)))]);
      if ((~mask) >> (j - 1) & 1) upd(dp[(j & 1)][mask], dp[(~j & 1)][mask]);
    }
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", (dp[(~L & 1)][arr[i]] == 0 ? -1 : dp[(~L & 1)][arr[i]]));
  return 0;
}
