#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  vector<long long int> b(5000001, -1);
  for (long long int i = 0; i < n; i++) {
    b[(~a[i]) & ((1 << 22) - 1)] = i;
  }
  for (long long int i = 0; i < 22; i++) {
    for (auto mask = 1; mask <= ((1 << 22) - 1); mask++) {
      if (mask & (1 << i) && b[mask] != -1) b[mask ^ (1 << i)] = b[mask];
    }
  }
  for (long long int i = 0; i < n; i++) {
    if (b[a[i]] == -1)
      cout << -1 << ' ';
    else
      cout << a[b[a[i]]] << ' ';
  }
  return 0;
}
