#include <bits/stdc++.h>
using namespace std;
int a[1000010], vis[1 << 22];
int main() {
  int n, mask = (1 << 22) - 1;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    vis[mask ^ a[i]] = a[i];
  }
  for (int i = mask; i >= 0; i--) {
    if (vis[i]) continue;
    for (int j = 0; j < 22; j++) {
      if (vis[i | (1 << j)]) {
        vis[i] = vis[i | (1 << j)];
        break;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (vis[a[i]])
      printf("%d ", vis[a[i]]);
    else
      printf("-1 ");
  }
}
