#include <bits/stdc++.h>
int n, a[10000005], f[10000005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    f[a[i]] = a[i];
  }
  for (int i = 0; i <= 22; i++)
    for (int j = 0; j < (1 << 22); j++)
      if ((j & (1 << i)) && f[j ^ (1 << i)]) f[j] = f[j ^ (1 << i)];
  for (int i = 1; i <= n; i++)
    printf("%d ", f[((1 << 22) - 1) ^ a[i]] ? f[((1 << 22) - 1) ^ a[i]] : -1);
  return 0;
}
