#include <bits/stdc++.h>
using namespace std;
int const N = 1 << 23;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n), dp(N, 0);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    dp[arr[i]] = arr[i];
  }
  for (int mask = 1; mask < N; ++mask) {
    for (int i = 0; (1 << i) <= mask; ++i) {
      if ((1 << i) & mask) {
        dp[mask] = (dp[mask ^ (1 << i)]) ? dp[mask ^ (1 << i)] : dp[mask];
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    int x = dp[(~arr[i]) & ((1 << 22) - 1)];
    if (!x) {
      cout << "-1 ";
      continue;
    }
    cout << x << " ";
  }
}
