#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, a[N];
int f[1 << 24];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), f[a[i] ^ ((1 << 23) - 1)] = a[i];
  for (int sta = (1 << 23) - 1; ~sta; --sta)
    if (!f[sta]) {
      for (int i = 0; i <= 23; ++i)
        if (f[sta | (1 << i)]) f[sta] = f[sta | (1 << i)];
    }
  for (int i = 1; i <= n; ++i) printf("%d ", f[a[i]] ? f[a[i]] : -1);
  return 0;
}
