#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
long double PI = 2 * acos(0.0);
template <typename T>
T gcd(T a, T b) {
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a * (b / gcd(a, b));
}
template <typename T>
T mod_exp(T b, T p, T m) {
  T x = 1;
  while (p) {
    if (p & 1) x = (x * b) % m;
    b = (b * b) % m;
    p = p >> 1;
  }
  return x;
}
template <typename T>
T invFermat(T a, T p) {
  return mod_exp(a, p - 2, p);
}
template <typename T>
T exp(T b, T p) {
  T x = 1;
  while (p) {
    if (p & 1) x = (x * b);
    b = (b * b);
    p = p >> 1;
  }
  return x;
}
string tostring(int number) {
  stringstream ss;
  ss << number;
  return ss.str();
}
int toint(const string& s) {
  stringstream ss;
  ss << s;
  int x;
  ss >> x;
  return x;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int maxm = (1 << 22) + 1;
int dp[maxm];
void solve() {
  memset(dp, -1, sizeof dp);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    int comp = ((1 << 22) - 1) ^ a[i];
    dp[comp] = a[i];
  }
  for (int i = maxm; i >= 0; i--) {
    for (int j = 0; j < 22; j++) {
      if (i & (1 << j)) {
        int comp = (i ^ (1 << j));
        if (dp[i] != -1) {
          dp[comp] = dp[i];
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << dp[a[i]] << " ";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
