#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii>
using vec = vector<T>;
const int N = 23;
const int MAX = 1 << N;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  vii f(MAX, -1);
  int n;
  cin >> n;
  vii v(n);
  for (auto &e : v) {
    cin >> e;
    f[e] = e;
  }
  for (int i = 1; i < MAX; i <<= 1) {
    for (int mask = 0; mask < MAX; mask++) {
      if (mask & i and f[mask ^ i] != -1) {
        f[mask] = f[mask ^ i];
      }
    }
  }
  for (int e : v) {
    cout << f[e ^ (MAX - 1)] << ' ';
  }
  cout << '\n';
}
