#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;

#define ll int
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)

#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)

#define swap(a,b){ auto _t=a;a=b,b=_t;}
// typedef __int128 bign;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define MD          1000000007
#define M 			1000011
#define LN 			14
#define fftmod      998244353
#define EPS         (double)1e-10

ll md=MD;
ll inf=2e18;

inline ll exp(ll a,ll b){ll r=1LL;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}

using cd=complex<double>;
const double PI=acos(-1);

vii g[M];
ll dp[1ll<<22][23];
ll ans[1ll<<22];
ll a[M];

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,x,y,n,s,z,p,k,T;string s1,s2;x=1;ll q;
    cin>>n;
    map<ll,ll> mp;
    ll N=22;
    lp(1,n)cin>>a[i],++mp[a[i]];
    for(ll mask=0;mask<(1<<N);++mask){
        dp[mask][0]=-1;
        if(mp.find(mask)!=mp.end())dp[mask][0]=mask;
        for(i=1;i<=N;++i){
            if(mask&(1ll<<(i-1))){
                if(dp[mask][i-1]>0)dp[mask][i]=dp[mask][i-1];
                if(dp[mask^(1ll<<(i-1))][i-1]>0)dp[mask][i]=dp[mask^(1ll<<(i-1))][i-1];

            }
            else{
                if(dp[mask][i-1]>0)
                    dp[mask][i]=dp[mask][i-1];
            }
        }
        ans[mask]=dp[mask][N];

        if(ans[mask]==0)ans[mask]=-1;

    }
    ll fo=(1ll<<22)-1;
    lp(1,n)cout<<ans[((1ll<<22)-1)^a[i]]<<" ";cout<<"\n";

    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;

#define ll long long int
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define all(x) x.begin(),x.end()
#define se second
#define fi first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)

#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)

#define swap(a,b){ auto _t=a;a=b,b=_t;}
// typedef __int128 bign;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define MD          1000000007
#define M 			1000011
#define LN 			14
#define fftmod      998244353
#define EPS         (double)1e-10

ll md=MD;
ll inf=2e18;

inline ll exp(ll a,ll b){ll r=1LL;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}

using cd=complex<double>;
const double PI=acos(-1);

vii g[M];
ll dp[1ll<<22][23];
ll a[M];

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,x,y,n,s,z,p,k,T;string s1,s2;x=1;ll q;
    cin>>n;
    unordered_map<ll,ll> mp;
    unordered_map<int,int> ans;
    ll N=22;
    lp(1,n)cin>>a[i],++mp[a[i]];
    for(ll mask=0;mask<(1<<N);++mask){
        dp[mask][0]=-1;
        if(mp.find(mask)!=mp.end())dp[mask][0]=mask;
        for(i=1;i<=N;++i){
            if(mask&(1ll<<(i-1))){
                if(dp[mask][i-1]>0)dp[mask][i]=dp[mask][i-1];
                if(dp[mask^(1ll<<(i-1))][i-1]>0)dp[mask][i]=dp[mask^(1ll<<(i-1))][i-1];

            }
            else{
                if(dp[mask][i-1]>0)
                    dp[mask][i]=dp[mask][i-1];
            }
        }

        if(dp[mask][N]>0)ans[mask]=dp[mask][N];

    }
    ll fo=(1ll<<22)-1;
    lp(1,n){
        if(ans.find(fo^a[i])!=ans.end())cout<<ans[fo^a[i]]<<" ";
        else cout<<"-1 ";
    }
    cout<<"\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")

#define ll  long long int
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;

#define MD          1000000007
#define M           100011
#define N 			22
long long  md=MD;
int F[1<<N];

int solve(){
	int n,i,j,k,m;
	cin>>n;
	memset(F,-1,sizeof(F));
	vector<int> v;
	for(i=0;i<n;++i){
		int x;
		cin>>x;
		v.pb(x);
		F[x]=x;
	}
	for(i=0;i<N;++i){
		for(j=0;j<(1<<N);++j){
			if(j&(1<<i)){
				F[j]=max(F[j],F[j^(1<<i)]);

			}
		}
	}
	for(int x:v){
		int po=((1<<N)-1)^x;
		// cerr<<po<<"\n";
		cout<<F[po]<<" ";
	}cout<<"\n";

}

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;

    t=1;
    // cin>>t;

    while(t--){
    	solve();
    }

}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(int i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(int (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 998244353
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    int n,te,arr[1000000],f[4200000];
    meme(f,-1);
    cin>>n;
    REP(0,n){cin>>arr[i];f[arr[i]]=arr[i];}
    REP(0,22){
        REPV(j,0,4194304){
            if((j&(1ll<<i)) && f[j&(1ll<<i)]!=-1)f[j]=f[j&(1ll<<i)];
        }
    }
    REP(0,n){
        cout<<f[(1ll<<22)-1-arr[i]]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 1000000007
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    long long dp[(1ll<<22)+10],arr[(1ll<<20)+10],n;
    meme(dp,-1);
    cin>>n;
    REP(0,n){cin>>arr[i];dp[arr[i]]=arr[i];}
    //cout<<"sad"<<endl;
    REP(0,1<<22){
        if(dp[i]>0)continue;
        REPV(j,0,22){
            if(i&(1<<j)){if(dp[i^(1<<j)]!=-1)dp[i]=dp[i^(1<<j)];}
        }
    }
    //cout<<"sad"<<endl;
    REP(0,n)cout<<dp[(1<<22)-1-arr[i]]<<" ";
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 1000000007
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    lo n,che[4000001],arr[1000000],dp[4194304+5][23];
    meme(che,0);
    meme(dp,-1);
    //cout<<dp[20][20]<<endl;
    cin>>n;
    REP(0,n){cin>>arr[i];che[arr[i]]=1;}
    REP(0,(1ll<<22)){
        if(che[i]==1){dp[i][0]=i;}
        if(i&1){if(che[i^1]==1)dp[i][0]=i^1;}
        REPV(j,1,23){
            if(dp[i][j-1]!=-1){dp[i][j]=dp[i][j-1];}
            if(i&(1ll<<j)){if(dp[i^(1<<j)][j-1]!=-1){dp[i][j]=dp[i^(1<<j)][j-1];}}
        }
    }
    REP(0,n)cout<<dp[(1ll<<22)-1-arr[i]][22]<<" ";
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef int lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 1000000007
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    int dp[(1ll<<22)+10],arr[(1ll<<20)+10],n;
    meme(dp,-1);
    cin>>n;
    REP(0,n){cin>>arr[i];dp[arr[i]]=arr[i];}
    //cout<<"sad"<<endl;
    REP(0,1<<22){
        if(dp[i]>0)continue;
        REPV(j,0,22){
            if(i&(1<<j)){if(dp[i^(1<<j)]!=-1)dp[i]=dp[i^(1<<j)];}
        }
    }
    //cout<<"sad"<<endl;
    REP(0,n)cout<<dp[(1<<22)-1-arr[i]]<<" ";
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef int lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 1000000007
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    int dp[(1ll<<22)+10],arr[(1ll<<20)+10],n;
    meme(dp,-1);
    //cin>>n;
    scanf("%d",&n);
    REP(0,n){//cin>>arr[i];
    scanf("%d",&arr[i]);
    dp[arr[i]]=arr[i];}
    //cout<<"sad"<<endl;
    REP(0,1<<22){
        if(dp[i]>0)continue;
        REPV(j,0,22){
            if(i&(1<<j)){if(dp[i^(1<<j)]!=-1)dp[i]=dp[i^(1<<j)];}
        }
    }
    //cout<<"sad"<<endl;
    REP(0,n)printf("%d ",dp[(1<<22)-1-arr[i]]);//cout<<dp[(1<<22)-1-arr[i]]<<" ";
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 1000000007
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    long n,arr[100000],dp[4194304+10][23],check[4194304+10];
    meme(check,0);meme(dp,-1);
    cin>>n;
    REP(0,n){cin>>arr[i];check[arr[i]]=1;}
    REP(0,(1<<22)){
        if(check[i]==1)dp[i][0]=i;
        if(i&1){if(check[i^1]==1)dp[i][0]=i^1;}
        REPV(j,1,23){
            if(dp[i][j-1]!=-1)dp[i][j]=dp[i][j-1];
            if(i&(1<<j)){
                if(dp[i^(1<<j)][j-1]!=-1)dp[i][j]=dp[i^(1<<j)][j-1];
            }
        }
    }
    REP(0,n){
        cout<<dp[(1<<22)-1-arr[i]][22]<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/seg_tree_policy.hpp> // Including seg_sum_order_statistics_node_update
#include <stdio.h>
#include <cassert>
using namespace std;
//using namespace __gnu_pbds;
typedef long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
typedef vector< vl > vvl;  //vector of vectors
#define X first
#define Y second
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(lo)b;i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(lo)d;j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for(lo (a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRV(a) for(auto it : a)
#define INF 300010
#define INFI 10000000000000000
#define MOD 1000000007
#define mod 10
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#define pb(a) push_back((a))
#define meme(a,b) memset(a, b, sizeof a)
#define BASE 1005LL
/*order statistic seg_sum
typedef
seg_sum<
  lo,
    null_type,
  less_equal<lo>,
  rb_seg_sum_tag,
  // This policy updates nodes' metadata for order statistics.
  seg_tree_order_statistics_node_update>
ordered_set;*/

template<typename T> ostream& operator<< ( ostream &o,vector<T> v ) {
    if ( v.size() >0 )o<<v[0];
    for ( unsigned   i=1; i<v.size(); i++ )o<<" "<<v[i];
    return o<<endl;
}
template<typename U,typename V> ostream& operator<< ( ostream &o,pair<U,V> p ) {
    return o<<"("<<p.first<<", "<<p.second<<") ";
}
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {
    for ( unsigned   i=0; i<v.size(); i++ )in>>v[i];
    return in;
}
template<typename T> istream& operator>> ( istream &in,pair <T,T> &p ) {
    in>>p.X;
    in>>p.Y;
    return in;
}
/*//tarjans for articulation points
long MAXX 100007
bool AP[MAXX];
vl adj[MAXX];
lo low[MAXX],parent[MAXX],disc[MAXX];
void ini()
{
  REP(0,MAXX)
  {
   vis[i]=AP[i]=false; // Initializing AP and vis array as false
   parent[i]=-1;         // Initializing parent of each vertex to -1
   adj[i].clear();        // clearing the adjacency list.
   low[i]=0;
  }
  tim=0;                    // initializing tim to 0
}

void dfs(lo u)
{
vis[u]=true;
low[u]=disc[u]=(++tim);
lo child=0;
  REP(0,adj[u].size())
  {
   lo v=adj[u][i];
   if(vis[v]==false)
   {
    child++;
    parent[v]=u;
    dfs(v);

    low[u]=min(low[u],low[v]);
    if( (parent[u]!=-1) and ( low[v]>=disc[u] ) )
      AP[u]=true;
     if( (parent[u]==-1) and (child>1))
      AP[u]=true;
   }
   else if(v!=parent[u])
    {low[u]=min(low[u],disc[v]);}
  }

}
*/

int main(){
    long n,arr[100000],dp[4194304+10][23],check[4194304+10];
    meme(check,0);meme(dp,-1);
    cin>>n;
    REP(0,n){cin>>arr[i];check[arr[i]]=1;}
    REP(0,(1ll<<22)){
        if(check[i]==1)dp[i][0]=i;
        if(i&1){if(check[i^1]==1)dp[i][0]=i^1;}
        REPV(j,1,23){
            if(dp[i][j-1]!=-1)dp[i][j]=dp[i][j-1];
            if(i&(1ll<<j)){
                if(dp[i^(1ll<<j)][j-1]!=-1)dp[i][j]=dp[i^(1ll<<j)][j-1];
            }
        }
    }
    REP(0,n){
        cout<<dp[(1ll<<22)-1-arr[i]][22]<<" ";
    }
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 21) + 100
#define INF 0x3f3f3f3f
#define N 21

int n , x[1000090] , dp[MAX][23];
int DP(int a , int b){

	if(dp[a][b] != 0) return dp[a][b];
	if(b == 21)       return dp[a][b] = -1;
	dp[a][b] = -1;
	if(a & (1 << b)) dp[a][b] = max(DP(a , b + 1) , DP(a - (1 << b) , b + 1));
	else 			 dp[a][b] = DP(a , b + 1);
	return dp[a][b];
}
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 1 , n + 1) dp[x[i]][21] = x[i];
	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 21) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		tmp = DP(tmp , 0);
		// if(tmp > 0 && (tmp & x[i]) != 0) cout << "wrong answer";
		cout << tmp << " ";
	}
	cout << endl;
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 22) + 100
#define INF 0x3f3f3f3f
#define N (1 << 22)

int n , x[MAX] , dp[MAX][2];
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 0 , N)     dp[i][0] = -1;
	REP(i , 1 , n + 1) dp[x[i]][0] = x[i];

	RREP(i , 21 , 0){
		int now = i % 2 , pre = (i + 1) % 2;
		REP(j , 0 , N){
			if(j & (1 << i)) dp[j][now] = max(dp[j][pre] , dp[j - (1 << i)][pre]);
			else 			 dp[j][now] = dp[j][pre];
		}
	}

	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 22) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		cout << dp[tmp][0] << " " ;
	}
	cout << endl;
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 22) + 100
#define INF 0x3f3f3f3f
#define N (1 << 22)

int n , x[MAX] , dp[MAX][2];
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 0 , N)     dp[i][1] = -1;
	REP(i , 1 , n + 1) dp[x[i]][1] = x[i];

	RREP(i , 22 , 0){
		int now = i % 2 , pre = (i + 1) % 2;
		REP(j , 0 , N){
			if(j & (1 << i)) dp[j][now] = max(dp[j][pre] , dp[j - (1 << i)][pre]);
			else 			 dp[j][now] = dp[j][pre];
		}
	}

	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 21) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		cout << dp[tmp][0] << " " ;
	}
	cout << endl;
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 22) + 100
#define INF 0x3f3f3f3f
#define N 22

int n , x[MAX] , dp[MAX][23];
int DP(int a , int b){

	if(dp[a][b] != 0) return dp[a][b];
	if(b == 22)       return dp[a][b] = -1;
	dp[a][b] = -1;
	if(a & (1 << b)) dp[a][b] = max(DP(a , b + 1) , DP(a - (1 << b) , b + 1));
	else 			 dp[a][b] = DP(a , b + 1);
	return dp[a][b];
}
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 1 , n + 1) dp[x[i]][22] = x[i];
	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 22) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		tmp = DP(tmp , 0);
		// if(tmp > 0 && (tmp & x[i]) != 0) cout << "wrong answer";
		cout << tmp << " ";
	}
	cout << endl;
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 24) + 100
#define INF 0x3f3f3f3f
#define N (1 << 24)

int n , x[MAX] , dp[MAX][2];
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 0 , N)     dp[i][0] = -1;
	REP(i , 1 , n + 1) dp[x[i]][0] = x[i];

	RREP(i , 23 , 0){
		int now = i % 2 , pre = (i + 1) % 2;
		REP(j , 0 , N){
			if(j & (1 << i)) dp[j][now] = max(dp[j][pre] , dp[j - (1 << i)][pre]);
			else 			 dp[j][now] = dp[j][pre];
		}
	}

	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 24) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		cout << dp[tmp][0] << " " ;
	}
	cout << endl;
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 23) + 100
#define INF 0x3f3f3f3f
#define N (1 << 23)

int n , x[MAX] , dp[MAX][2];
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 0 , N)     dp[i][1] = -1;
	REP(i , 1 , n + 1) dp[x[i]][1] = x[i];

	RREP(i , 22 , 0){
		int now = i % 2 , pre = (i + 1) % 2;
		REP(j , 0 , N){
			if(j & (1 << i)) dp[j][now] = max(dp[j][pre] , dp[j - (1 << i)][pre]);
			else 			 dp[j][now] = dp[j][pre];
		}
	}

	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 23) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		cout << dp[tmp][0] << " " ;
	}
	cout << endl;
    return 0;
}


/*input
5
10 6 9 8 2
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX (1 << 22) + 100
#define INF 0x3f3f3f3f
#define N 22

int n , x[MAX] , dp[MAX][24];
int DP(int a , int b){

	if(dp[a][b] != 0) return dp[a][b];
	if(b == 23)       return dp[a][b] = -1;
	dp[a][b] = -1;
	if(a & (1 << b)) dp[a][b] = max(DP(a , b + 1) , DP(a - (1 << b) , b + 1));
	else 			 dp[a][b] = DP(a , b + 1);
	return dp[a][b];
}
int32_t main(){
	IOS , cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	REP(i , 1 , n + 1) dp[x[i]][23] = x[i];
	REP(i , 1 , n + 1){
		int tmp = 0;
		REP(j , 0 , 22) if((x[i] & (1 << j)) == 0) tmp |= (1 << j);
		tmp = DP(tmp , 0);
		// if(tmp > 0 && (tmp & x[i]) != 0) cout << "wrong answer";
		cout << tmp << " ";
	}
	cout << endl;
    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 22;
int n , a[N] , ans;

struct Trie
{
    Trie *T[2];
    int c[2];
    Trie()
    {
        memset(c , 0 , sizeof c);
        memset(T , 0 , sizeof T);
    }

    void add(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        if(!T[x]) T[x] = new Trie();
        c[x]++;
        T[x]->add(s , i + 1);
    }

    void del(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        c[x]--;
        T[x]->del(s , i + 1);
    }

    bool getAns(string &s , int i)
    {
        if(i == M) return 1;
        int x = s[i] - '0';

        if(x == 1)
        {
            if(!c[!x] ) return 0;
            T[!x]->getAns(s , i + 1);
        }
        else
        {
            bool re = 0;
            if(c[x])
                re = T[x]->getAns(s , i + 1);
            if(!re && c[!x])
            {
                re = T[!x]->getAns(s , i + 1);
                if(re)
                    ans += (1 << i);
            }
            return re;
        }
    }
}T;

string toBin(int x)
{
    string s;
    while(x)
    {
        s += (x % 2) + '0';
        x /= 2;
    }

    while(s.size() < M)
        s += "0";

    return s;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        string s = toBin(a[i]);
        T.add(s , 0);
    }

    for(int i = 0 ; i < n ; i++)
    {
        ans = 0;
        string s = toBin(a[i]);
        T.del(s , 0);
        if(T.getAns(s , 0))
            cout << ans << " ";
        else
            cout << -1 << " ";
        T.add(s , 0);
    }

    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 22;
int n , a[N] , dp[1 << M];

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    memset(dp , -1 ,sizeof dp);
    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];

        queue<int> q;
        q.push((a[i] ^ ((1 << M) - 1) ));
        while(!q.empty())
        {
            int x = q.front();
            q.pop();

            dp[x] = a[i];
            for(int k = 0 ; k < M ; k++)
                if(x & (1 << k) && dp[x ^ (1 << k)] == -1)
                    dp[x ^ (1 << k)] = a[i] , q.push(x ^ (1 << k));
        }
    }

    for(int i = 0 ; i < n ; i++)
        cout << dp[a[i]] << " ";

    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 23;
int n , a[N] , ans;

struct Trie
{
    Trie *T[2];
    int c[2];
    Trie()
    {
        memset(c , 0 , sizeof c);
        memset(T , 0 , sizeof T);
    }

    void add(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        if(!T[x]) T[x] = new Trie();
        c[x]++;
        T[x]->add(s , i + 1);
    }

    void del(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        c[x]--;
        T[x]->del(s , i + 1);
    }

    bool getAns(string &s , int i)
    {
        if(i == M) return 1;
        int x = s[i] - '0';

        if(x == 1)
        {
            if(!c[!x] ) return 0;
            T[!x]->getAns(s , i + 1);
        }
        else
        {
            bool re = 0;
            if(c[x])
                re = T[x]->getAns(s , i + 1);
            if(!re && c[!x])
            {
                re = T[!x]->getAns(s , i + 1);
                if(re)
                    ans += (1 << i);
            }
            return re;
        }
    }
}T;

string toBin(int x)
{
    string s;
    while(x)
    {
        s += (x % 2) + '0';
        x /= 2;
    }

    while(s.size() < M)
        s += "0";

    return s;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        string s = toBin(a[i]);
        T.add(s , 0);
    }

    for(int i = 0 ; i < n ; i++)
    {
        ans = 0;
        string s = toBin(a[i]);
        T.del(s , 0);
        if(T.getAns(s , 0))
            cout << ans << " ";
        else
            cout << -1 << " ";
        T.add(s , 0);
    }

    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 22;
int n , a[N] , ans , dp[1 << M][M];

struct Trie
{
    Trie *T[2];
    int c[2];
    Trie()
    {
        memset(c , 0 , sizeof c);
        memset(T , 0 , sizeof T);
    }

    void add(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        if(!T[x]) T[x] = new Trie();
        c[x]++;
        T[x]->add(s , i + 1);
    }

    void del(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        c[x]--;
        T[x]->del(s , i + 1);
    }

    int getAns(string &s , int i , int msk)
    {
        if(i == M) return 0;

        int &ret = dp[msk][i];
        if(~ret) return ret;

        int x = s[i] - '0';
        if(x == 1)
        {
            if(!c[!x] ) return -1;
            return ret = T[!x]->getAns(s , i + 1 , max( 0 , msk - (1 << i)) );
        }
        else
        {
            if(c[x])
                ret = T[x]->getAns(s , i + 1 , msk);

            if(ret == -1 && c[!x])
            {
                ret = T[!x]->getAns(s , i + 1 , max(0 , msk - (1 << i)) );
                if(~ret)
                    ret += (1 << i);
            }
            return ret;
        }
    }
}T;

string toBin(int x)
{
    string s;
    while(x)
    {
        s += (x % 2) + '0';
        x /= 2;
    }

    while(s.size() < M)
        s += "0";

    return s;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        string s = toBin(a[i]);
        T.add(s , 0);
    }

    memset(dp , -1 ,sizeof dp);
    for(int i = 0 ; i < n ; i++)
    {
        ans = 0;
        string s = toBin(a[i]);
        T.del(s , 0);
        cout << T.getAns(s , 0 , a[i]) << " ";
        T.add(s , 0);
    }

    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 20;
int n , a[N] , ans;

struct Trie
{
    Trie *T[2];
    int c[2];
    Trie()
    {
        memset(c , 0 , sizeof c);
        memset(T , 0 , sizeof T);
    }

    void add(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        if(!T[x]) T[x] = new Trie();
        c[x]++;
        T[x]->add(s , i + 1);
    }

    void del(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        c[x]--;
        T[x]->del(s , i + 1);
    }

    bool getAns(string &s , int i)
    {
        if(i == M) return 1;
        int x = s[i] - '0';

        if(x == 1)
        {
            if(!c[!x] ) return 0;
            T[!x]->getAns(s , i + 1);
        }
        else
        {
            bool re = 0;
            if(c[x])
                re = T[x]->getAns(s , i + 1);
            if(!re && c[!x])
            {
                re = T[!x]->getAns(s , i + 1);
                if(re)
                    ans += (1 << i);
            }
            return re;
        }
    }
}T;

string toBin(int x)
{
    string s;
    while(x)
    {
        s += (x % 2) + '0';
        x /= 2;
    }

    while(s.size() < M)
        s += "0";

    return s;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        string s = toBin(a[i]);
        T.add(s , 0);
    }

    for(int i = 0 ; i < n ; i++)
    {
        ans = 0;
        string s = toBin(a[i]);
        T.del(s , 0);
        if(T.getAns(s , 0))
            cout << ans << " ";
        else
            cout << -1 << " ";
        T.add(s , 0);
    }

    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 31;
int n , a[N] , ans;

struct Trie
{
    Trie *T[2];
    int c[2];
    Trie()
    {
        memset(c , 0 , sizeof c);
        memset(T , 0 , sizeof T);
    }

    void add(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        if(!T[x]) T[x] = new Trie();
        c[x]++;
        T[x]->add(s , i + 1);
    }

    void del(string &s , int i)
    {
        if(i == M) return;
        int x = s[i] - '0';
        c[x]--;
        T[x]->del(s , i + 1);
    }

    bool getAns(string &s , int i)
    {
        if(i == M) return 1;
        int x = s[i] - '0';

        if(x == 1)
        {
            if(!c[!x] ) return 0;
            T[!x]->getAns(s , i + 1);
        }
        else
        {
            bool re = 0;
            if(c[x])
                re = T[x]->getAns(s , i + 1);
            if(!re && c[!x])
            {
                re = T[!x]->getAns(s , i + 1);
                if(re)
                    ans += (1 << i);
            }
            return re;
        }
    }
}T;

string toBin(int x)
{
    string s;
    while(x)
    {
        s += (x % 2) + '0';
        x /= 2;
    }

    while(s.size() < M)
        s += "0";

    return s;
}

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        string s = toBin(a[i]);
        T.add(s , 0);
    }

    for(int i = 0 ; i < n ; i++)
    {
        ans = 0;
        string s = toBin(a[i]);
        T.del(s , 0);
        if(T.getAns(s , 0))
            cout << ans << " ";
        else
            cout << -1 << " ";
        T.add(s , 0);
    }

    return 0;
}


#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

const int N = 1e6 + 6 , M = 22;
int n , a[N] , dp[1 << M];

int main()
{
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);

    memset(dp , -1 ,sizeof dp);
    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];

        dp[ (a[i] ^ ((1 << M) - 1) ) ] = a[i];
        for(int j = (a[i] ^ (1 << M) - 1) ; j >= 0 ; j--)
            if(~dp[j] && !(j & a[i]) )
                for(int k = 0 ; k < M ; k++)
                    if(j & (1 << k))
                        dp[j ^ (1 << k)] = a[i];
    }

    for(int i = 0 ; i < n ; i++)
        cout << dp[a[i]] << " ";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1010101;

int v[maxn];
int dp[1<<23];

int solve(int x)
{
	if (dp[x] >= 0) return dp[x];

	dp[x] = 0;

	for (int i = x; i and !dp[x]; i -= i&-i) {

		int xx = x^(i&-i);

		dp[x] |= solve(xx);
	}

	return dp[x];
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);

	int n;
	cin >> n;

	int maxi = 0;

	for (int i = 0; i < n; i++) {

		cin >> v[i];
		maxi = max(maxi, ((1<<23)-1)^v[i]);
		dp[v[i]] = v[i];
	}

	for (int x = 1; x <= maxi; x++) {

		for (int i = x; i and !dp[x]; i -= i&-i) {

			int xx = x^(i&-i);

			dp[x] = dp[xx];
		}
	}

	for (int i = 0; i < n; i++) {

		int x = ((1<<23)-1)^v[i];
		int ans = dp[x];

		if (ans == 0) cout << -1 << " ";
		else cout << ans << " ";
	}

	cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1010101;

int v[maxn];
int dp[1<<23];

int solve(int x)
{
	if (dp[x] >= 0) return dp[x];

	dp[x] = 0;

	for (int i = 0; i < 23; i++) {

		if (!(x&(1<<i))) continue;

		int xx = x^(1<<i);

		dp[x] = max(dp[x], solve(xx));
	}

	return dp[x];
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);

	memset(dp, -1, sizeof(dp));

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> v[i];

		dp[v[i]] = v[i];
	}

	for (int i = 0; i < n; i++) {

		int x = ((1<<23)-1)^v[i];
		int ans = solve(x);

		if (ans == 0) cout << -1 << " ";
		else cout << ans << " ";
	}

	cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1010101;

int v[maxn];
int dp[1<<23];

int solve(int x)
{
	if (dp[x] >= 0) return dp[x];

	dp[x] = 0;

	for (int i = x; i and !dp[x]; i -= i&-i) {

		int xx = x^(i&-i);

		dp[x] = max(dp[x], solve(xx));
	}

	return dp[x];
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);

	memset(dp, -1, sizeof(dp));

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> v[i];

		dp[v[i]] = v[i];
	}

	for (int i = 0; i < n; i++) {

		int x = ((1<<23)-1)^v[i];
		int ans = solve(x);

		if (ans == 0) cout << -1 << " ";
		else cout << ans << " ";
	}

	cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1010101;

int v[maxn];
int dp[1<<23];

int solve(int x)
{
	if (dp[x] >= 0) return dp[x];

	dp[x] = 0;

	for (int i = x; i and !dp[x]; i -= i&-i) {

		int xx = x^(i&-i);

		dp[x] |= solve(xx);
	}

	return dp[x];
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> v[i];

		dp[v[i]] = v[i];
	}

	for (int x = 1; x < (1<<23); x++) {

		for (int i = x; i and !dp[x]; i -= i&-i) {

			int xx = x^(i&-i);

			dp[x] |= dp[xx];
		}
	}

	for (int i = 0; i < n; i++) {

		int x = ((1<<23)-1)^v[i];
		int ans = dp[x];

		if (ans == 0) cout << -1 << " ";
		else cout << ans << " ";
	}

	cout << "\n";
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 1010101;

int v[maxn];
int dp[1<<23];

int solve(int x)
{
	if (dp[x] >= 0) return dp[x];

	dp[x] = 0;

	for (int i = x; i and !dp[x]; i -= i&-i) {

		int xx = x^(i&-i);

		dp[x] |= solve(xx);
	}

	return dp[x];
}

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);

	memset(dp, -1, sizeof(dp));

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {

		cin >> v[i];

		dp[v[i]] = v[i];
	}

	for (int i = 0; i < n; i++) {

		int x = ((1<<23)-1)^v[i];
		int ans = solve(x);

		if (ans == 0) cout << -1 << " ";
		else cout << ans << " ";
	}

	cout << "\n";
}


#include<bits/stdc++.h>
#include<bitset>
using namespace std;
const int m = 1<<24;
int f[m], a[m];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	for(int i=0; i<m; i++) f[i] = -1;
	int n;
	cin>>n;
	for(int i=0; i <n ;i++) cin>>a[i], f[m-1&~a[i]] = a[i];
	int k = 0;
	for(int j=m-1; j>0; j--)if(~f[j]){
		for(int i = j; i; i -= k){
			k = i & -i;
			f[j^k] = f[j];
		}
	}
	for(int i=0; i<n;i++) cout<<f[a[i]]<<" ";
	cout<<endl;
}


#include<bits/stdc++.h>
#include<bitset>
using namespace std;
const int m = 1<<24;
int f[m], a[m];
int main()
{
	for(int i=0; i<m; i++) f[i] = -1;
	int n;
	cin>>n;
	for(int i=0; i <n ;i++) cin>>a[i], f[m-1&~a[i]] = a[i];
	int k = 0;
	for(int j=m-1; j; j--)if(~f[j]){
		for(int i = j; i; i -= k){
			k = i & -i;
			f[j^k] = f[j];
		}
	}
	for(int i=0; i<n;i++) cout<<f[a[i]]<<" ";
	cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 4e6 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
ll caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
ll calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
ll Rnck(int big){if(big){caliv();}else{calf();}}
map<int, vector<int>> mp;
bool dp[22][N];
void solve()
{
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0; i<n; i++){
    int x;
    cin>>x;
    v.pb(x);
    for(int j = 0; j < 22; j++){
      if(((x>>j)&1) == 0){
        mp[j].pb(x);
        dp[j][x] = 1;
      }
    }
  }
  vector<int> ans;
  for(int i=0; i<n; i++){
    int c = v[i];
    vector<int> on;
    for(int j=0; j<22; j++){
      if(((c>>j)&1) == 1){
        on.pb(j);
      }
    }
    bool isok = false;
    int z = on[0];
    for(int x: mp[z]){
      bool ok = true;
      for(int j=1; j<on.size(); j++){
        if(dp[on[j]][x] == 0){
          ok =false;
          break;
        }
      }
      if(ok){
        ans.pb(x);
        isok = true;
         break;
      }
    }
    if(isok == false){
      ans.pb(-1);
    }
  }
  for(int x:ans) cout<<x<<" ";
  cout<<endl;
}

int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int m = 1 << 24;
int a[m], f[m], i, j, k;
int main()
{
int n;
for(scanf("%d ", &n); j <m ; j++) f[j] =-1;
for(;i<n;i++)scanf("%d", &a[i]), f[m-1&~a[i]] = a[i];
for(;--j;)if(~f[j])for(int i=j;i;i-=k) f[j^(k=i&-i)] = f[j];
for(int i=0; i<n; i++) printf("%d ", f[a[i]]);
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 4e6 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
ll caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
ll calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
ll Rnck(int big){if(big){caliv();}else{calf();}}
map<int, vector<int>> mp;
map<int, int> dp[25];
void solve()
{
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0; i<n; i++){
    int x;
    cin>>x;
    v.pb(x);
    for(int j = 0; j < 25; j++){
      if(((x>>j)&1) == 0){
        mp[j].pb(x);
        dp[j][x] = 1;
      }
    }
  }
  vector<int> ans;
  for(int i=0; i<n; i++){
    int c = v[i];
    vector<int> on;
    for(int j=0; j<25; j++){
      if(((c>>j)&1) == 1){
        on.pb(j);
      }
    }
    bool isok = false;
    int z = on[0];
    for(int x: mp[z]){
      bool ok = true;
      for(int j=1; j<on.size(); j++){
        if(dp[on[j]][x] == 0){
          ok =false;
          break;
        }
      }
      if(ok){
        ans.pb(x);
        isok = true;
         break;
      }
    }
    if(isok == false){
      ans.pb(-1);
    }
  }
  for(int x:ans) cout<<x<<" ";
  cout<<endl;
}

int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
const int N = 4e6 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
ll caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
ll calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
ll Rnck(int big){if(big){caliv();}else{calf();}}
map<int, vector<int>> mp;
map<int, int> dp[22];
void solve()
{
  int n;
  cin>>n;
  vector<int> v;
  for(int i=0; i<n; i++){
    int x;
    cin>>x;
    v.pb(x);
    for(int j = 0; j < 22; j++){
      if(((x>>j)&1) == 0){
        mp[j].pb(x);
        dp[j][x] = 1;
      }
    }
  }
  vector<int> ans;
  for(int i=0; i<n; i++){
    int c = v[i];
    vector<int> on;
    for(int j=0; j<22; j++){
      if(((c>>j)&1) == 1){
        on.pb(j);
      }
    }
    bool isok = false;
    int z = on[0];
    for(int x: mp[z]){
      bool ok = true;
      for(int j=1; j<on.size(); j++){
        if(dp[on[j]][x] == 0){
          ok =false;
          break;
        }
      }
      if(ok){
        ans.pb(x);
        isok = true;
         break;
      }
    }
    if(isok == false){
      ans.pb(-1);
    }
  }
  for(int x:ans) cout<<x<<" ";
  cout<<endl;
}

int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
ll dp[1<<23],t,n,a[1000006];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll i,j,k,ans;
    //cin>>t;
    t=1;
    while(t--)
    {
        memset(dp,-1,sizeof dp);
        ans=0;
        cin>>n;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            dp[a[i]]=a[i];
        }
        for(i=1;i<(1<<22);i++)
        {
            if(dp[i]==-1)
            continue;
            for(j=0;j<22;j++)
            {
                dp[i|(1<<j)]=dp[i];
            }
        }
        for(i=1;i<=n;i++)
        {
            j=a[i];
            cout<<dp[j^((1<<22)-1)];
            if(i!=n)
            cout<<" ";
        }
        if(t!=0)
        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
ll dp[1<<23],t,n,a[1000006];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll i,j,k,ans;
    cin>>t;
    while(t--)
    {
        memset(dp,-1,sizeof dp);
        ans=0;
        cin>>n;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            dp[a[i]]=a[i];
        }
        for(i=1;i<(1<<22);i++)
        {
            if(dp[i]==-1)
            continue;
            for(j=0;j<20;j++)
            {
                dp[i|(1<<j)]=dp[i];
            }
        }
        for(i=1;i<=n;i++)
        {
            j=a[i];
            cout<<dp[j^((1<<22)-1)];
            if(i!=n)
            cout<<" ";
        }
        if(t!=0)
        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
ll dp[1<<23],t,n,a[1000006];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll i,j,k,ans;
    //cin>>t;
    t=1;
    while(t--)
    {
        memset(dp,-1,sizeof dp);
        ans=0;
        cin>>n;
        for(i=1;i<=n;i++)
        {
            cin>>a[i];
            dp[a[i]]=a[i];
        }
        for(i=1;i<(1<<22);i++)
        {
            if(dp[i]==-1)
            continue;
            for(j=0;j<20;j++)
            {
                dp[i|(1<<j)]=dp[i];
            }
        }
        for(i=1;i<=n;i++)
        {
            j=a[i];
            cout<<dp[j^((1<<22)-1)];
            if(i!=n)
            cout<<" ";
        }
        if(t!=0)
        cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll int
#define MOD 1000000007
ll par[9000006],a[9000006],vis[9000006],n;
void dfs(ll num,ll val)
{
    vis[num]=1;
    par[num]=val;
    for(ll i=0;i<=22;i++)
    {
        if((num&(1<<i))==0)
        {
            if(!vis[num|(1<<i)])
            {
                dfs(num|(1<<i),val);
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll i,j,k;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<=n;i++)
    {
        if(!vis[a[i]])
        dfs(a[i],a[i]);
    }
    for(i=1;i<=n;i++)
    {
        j=(1<<22)-1-a[i];
        if(par[j]==0)
        cout<<"-1 ";
        else
        cout<<par[j]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define bob __builtin_popcount
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll roh[(1<<20)];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)cin>>a[i],roh[a[i]]=a[i];
    for(i=0;i<20;i++)
    {
        for(j=0;j<(1<<20);j++)
        {
            if(j&(1<<i))
            {
                if(roh[j] && roh[j^(1<<i)])roh[j]=roh[j^(1<<i)];
                else roh[j]+=roh[j^(1<<i)];
            }
        }
    }
    k=(1<<20);
    k--;
    for(i=0;i<n;i++)
    {
        if(roh[k^a[i]]==0)cout<<-1<<" ";
        else cout<<roh[k^a[i]]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll dp[1<<22];
ll ans[1<<22];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    um<ll,ll>z;
    for(i=0;i<n;i++)cin>>a[i],z[a[i]]++;
    mms(ans,-1);
    for(i=0;i<(1<<22);i++)
    {
        dp[i]=z[i];
        if(z[i]>0)ans[i]=i;
    }
    for(i=0;i<22;i++)
    {
        for(j=0;j<(1<<22);j++)
        {
            if(j&(1<<i))
            {
                dp[j]+=dp[j^(1<<i)];
                if(ans[j]==-1)ans[j]=ans[j^(1<<i)];
            }
        }
    }
    for(i=0;i<n;i++)
    {
       cout<<ans[a[i]^((1<<22)-1)]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define bob __builtin_popcount
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll roh[(1<<22)];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)cin>>a[i],roh[a[i]]=a[i];
    for(i=0;i<22;i++)
    {
        for(j=0;j<(1<<22);j++)
        {
            if(j&(1<<i))
            {
                if(roh[j] && roh[j^(1<<i)])roh[j]=roh[j^(1<<i)];
                else roh[j]+=roh[j^(1<<i)];
            }
        }
    }
    k=(1<<22);
    k--;
    for(i=0;i<n;i++)
    {
        if(roh[k^a[i]]==0)cout<<-1<<" ";
        else cout<<roh[k^a[i]]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define bob __builtin_popcount
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll dp[1<<22];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    mms(dp,-1);
    for(i=0;i<n;i++)cin>>a[i],dp[a[i]]=a[i];
    for(i=0;i<(1<<22);i++)
    {
        for(j=0;j<22;j++)
        {
            if(i&(1<<j))
            {
                if(dp[i]==-1)dp[i]=dp[i^(1<<j)];
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<dp[((1<<22)-1)^(a[i])]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define bob __builtin_popcount
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll dp[(1<<22)];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    mms(dp,-1);
    for(i=0;i<n;i++)cin>>a[i],dp[a[i]]=a[i];
    for(i=0;i<22;i++)
    {
        for(j=0;j<(1<<22);j++)
        {
            if(j&(1<<i))
            {
                if(dp[j]==-1)dp[j]=dp[j^(1<<i)];
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<dp[((1<<22)-1)^a[i]]<<" ";
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define bob __builtin_popcount
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll dp[1<<20];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    mms(dp,-1);
    for(i=0;i<n;i++)cin>>a[i],dp[a[i]]=a[i];
    for(i=0;i<(1<<20);i++)
    {
        for(j=0;j<20;j++)
        {
            if(i&(1<<j))
            {
                if(dp[i]==-1)dp[i]=dp[i^(1<<j)];
            }
        }
    }
    for(i=0;i<n;i++)
    {
        cout<<dp[((1<<20)-1)^(a[i])]<<" ";
    }
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> pii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pii> vpii;
typedef long long int ll;
typedef unsigned long long int ull;

#define mi 1000000007
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define pr(arr,n) rep(i,0,n) cout<<arr[i]<<" "; cout<<endl;
#define pr1(arr,n) rep(i,1,n+1) cout<<arr[i]<<" "; cout<<endl;
#define inf INT_MAX
#define gc getchar_unlocked
#define PB push_back
#define MP make_pair
#define fi first
#define se second
#define SET(a,b) memset(a,b,sizeof(a))
#define MAX 500005
#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

int mult(int x,int y)
{
  ll ans,x1=(ll)x,y1=(ll)y;
  ans=(x1*y1)%mi;
  return (int)ans;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}

ll pow1(ll a,ll b)
{
  ll ans=1;
  while(b>0)
    {
      if(b&1) ans=(ans*a)%mi;
      a=(a*a)%mi; b>>=1;
    }
  return ans;
}
int a[420005],arr[4200005];
int ans[4200005];
int main()
{
  int t,n,i,j;
  si(n);
  int mx=0;
  rep(i,1,n+1)
    {
      si(a[i]); mx=max(mx,a[i]);
      arr[a[i]]++;
    }
    int n1=ceil(log2(mx));
    int tmp=(1<<n1)-1;
    rep(i,1,mx+1)
      {
	ll cnt=0;
	if(arr[i]>0)
	  {
	    int val=(tmp^i);
	    //trace2(val,i);
	    for(j=val;j>0;j=((j-1)&val))
	      if(arr[j] && j!=i)
		ans[i]=j;
	  }
      }
    rep(i,1,n+1)
      if(!ans[a[i]]) printf("-1 ");
      else printf("%d ",ans[a[i]]);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> pii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pii> vpii;
typedef long long int ll;
typedef unsigned long long int ull;

#define mi 1000000007
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define pr(arr,n) rep(i,0,n) cout<<arr[i]<<" "; cout<<endl;
#define pr1(arr,n) rep(i,1,n+1) cout<<arr[i]<<" "; cout<<endl;
#define inf INT_MAX
#define gc getchar_unlocked
#define PB push_back
#define MP make_pair
#define fi first
#define se second
#define SET(a,b) memset(a,b,sizeof(a))
#define MAX 500005
#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

int mult(int x,int y)
{
  ll ans,x1=(ll)x,y1=(ll)y;
  ans=(x1*y1)%mi;
  return (int)ans;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}

ll pow1(ll a,ll b)
{
  ll ans=1;
  while(b>0)
    {
      if(b&1) ans=(ans*a)%mi;
      a=(a*a)%mi; b>>=1;
    }
  return ans;
}
int a[400005],arr[4000005];
int ans[4000005];
int main()
{
  int t,n,i,j;
  si(n);
  int mx=0;
  rep(i,1,n+1)
    {
      si(a[i]); mx=max(mx,a[i]);
      arr[a[i]]++;
    }
    int n1=ceil(log2(mx));
    int tmp=(1<<n1)-1;
    rep(i,1,mx+1)
      {
	ll cnt=0;
	if(arr[i]>0)
	  {
	    int val=(tmp^i);
	    for(j=val;j>0;j=((j-1)&val))
	      if(arr[j])
		ans[i]=j;
	  }
      }
    rep(i,1,n+1)
      if(!ans[a[i]]) printf("-1 ");
      else printf("%d ",ans[a[i]]);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> pii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pii> vpii;
typedef long long int ll;
typedef unsigned long long int ull;

#define mi 1000000007
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define pr(arr,n) rep(i,0,n) cout<<arr[i]<<" "; cout<<endl;
#define pr1(arr,n) rep(i,1,n+1) cout<<arr[i]<<" "; cout<<endl;
#define inf INT_MAX
#define gc getchar_unlocked
#define PB push_back
#define MP make_pair
#define fi first
#define se second
#define SET(a,b) memset(a,b,sizeof(a))
#define MAX 500005
#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

int mult(int x,int y)
{
  ll ans,x1=(ll)x,y1=(ll)y;
  ans=(x1*y1)%mi;
  return (int)ans;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}

ll pow1(ll a,ll b)
{
  ll ans=1;
  while(b>0)
    {
      if(b&1) ans=(ans*a)%mi;
      a=(a*a)%mi; b>>=1;
    }
  return ans;
}
int a[4200005],dp[4200005];
int main()
{
  int n,i,j;
  si(n);
  rep(i,1,n+1)
    {
      si(a[i]);
      dp[a[i]]=a[i];
    }
  int tot=(1<<22);
  rep(i,0,22)
    {
      rep(j,0,tot)
	{
	  if(j&(1<<i) && !dp[j])
	    dp[j]=dp[j^(1<<i)];
	}
    }
  rep(i,1,n+1)
    {
      if(!dp[tot-1-a[i]])
	printf("-1 ");
      else
	printf("%d ",dp[tot-1-a[i]]);
    }
  printf("\n");
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> pii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pii> vpii;
typedef long long int ll;
typedef unsigned long long int ull;

#define mi 1000000007
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define pr(arr,n) rep(i,0,n) cout<<arr[i]<<" "; cout<<endl;
#define pr1(arr,n) rep(i,1,n+1) cout<<arr[i]<<" "; cout<<endl;
#define inf INT_MAX
#define gc getchar_unlocked
#define PB push_back
#define MP make_pair
#define fi first
#define se second
#define SET(a,b) memset(a,b,sizeof(a))
#define MAX 500005
#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

int mult(int x,int y)
{
  ll ans,x1=(ll)x,y1=(ll)y;
  ans=(x1*y1)%mi;
  return (int)ans;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}

ll pow1(ll a,ll b)
{
  ll ans=1;
  while(b>0)
    {
      if(b&1) ans=(ans*a)%mi;
      a=(a*a)%mi; b>>=1;
    }
  return ans;
}
int a[400005],arr[4000005];
int ans[4000005];
int main()
{
  int t,n,i,j;
  si(n);
  int mx=0;
  rep(i,1,n+1)
    {
      si(a[i]); mx=max(mx,a[i]);
      arr[a[i]]++;
    }
    int n1=ceil(log2(mx));
    int tmp=(1<<n1)-1;
    rep(i,1,mx+1)
      {
	ll cnt=0;
	if(arr[i]>0)
	  {
	    int val=(tmp^i);
	    for(j=val;j>0;j=((j-1)&val))
	      if(arr[j] && j!=i)
		ans[i]=j;
	  }
      }
    rep(i,1,n+1)
      if(!ans[a[i]]) printf("-1 ");
      else printf("%d ",ans[a[i]]);
    printf("\n");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> pii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pii> vpii;
typedef long long int ll;
typedef unsigned long long int ull;

#define mi 1000000007
#define rep(i,a,b) for(i=a;i<b;i++)
#define repv(i,a,b) for(i=b-1;i>=a;i--)
#define pr(arr,n) rep(i,0,n) cout<<arr[i]<<" "; cout<<endl;
#define pr1(arr,n) rep(i,1,n+1) cout<<arr[i]<<" "; cout<<endl;
#define inf INT_MAX
#define gc getchar_unlocked
#define PB push_back
#define MP make_pair
#define fi first
#define se second
#define SET(a,b) memset(a,b,sizeof(a))
#define MAX 500005
#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

int mult(int x,int y)
{
  ll ans,x1=(ll)x,y1=(ll)y;
  ans=(x1*y1)%mi;
  return (int)ans;
}
int gcd(int a,int b) { return b==0 ? a : gcd (b,a%b);}
int lcm(int a,int b) { return a*(b/gcd(a,b));}

ll pow1(ll a,ll b)
{
  ll ans=1;
  while(b>0)
    {
      if(b&1) ans=(ans*a)%mi;
      a=(a*a)%mi; b>>=1;
    }
  return ans;
}
int a[4200005],arr[4200005];
int ans[4200005];
int main()
{
  int t,n,i,j;
  si(n);
  int mx=0;
  rep(i,1,n+1)
    {
      si(a[i]); mx=max(mx,a[i]);
      arr[a[i]]++;
    }
    int n1=ceil(log2(mx));
    int tmp=(1<<n1)-1;
    rep(i,1,mx+1)
      {
	ll cnt=0;
	if(arr[i]>0)
	  {
	    int val=(tmp^i);
	    //trace2(val,i);
	    for(j=val;j>0;j=((j-1)&val))
	      if(arr[j] && j!=i)
		ans[i]=j;
	  }
      }
    rep(i,1,n+1)
      if(!ans[a[i]]) printf("-1 ");
      else printf("%d ",ans[a[i]]);
    printf("\n");
    return 0;
}


// abhishek soni.....[NSIT'22]

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

#define letsgo              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                '\n'
#define ff                  first
#define ss                  second
#define int                 long long
#define ll                  long long
#define mp                  make_pair
#define pb                  push_back
#define pf                  push_front
#define lb                  lower_bound
#define ub                  upper_bound
#define ALL(x)              (x).begin() , (x).end()
#define set_bits(x)         __builtin_popcountll(x)
#define unset_bits(x)       __builtin_ctzll(x)
#define fl(i,a,b)           for(int i = a ; i < b ; i++)
#define bl(i,a,b)           for(int i = a ; i >= b ; i--)

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> pbds;

typedef pair<int,int>                                   pii;
typedef pair<int,pair<int,int>>                         piii;
typedef pair<pair<int,int>,pair<int,int>>               piiii;
typedef priority_queue<int>                             maxpq;
typedef priority_queue<int,vector<int>,greater<int>>    minpq;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int pow(int a,int b,int m){
    if(a == 0) return 0;
    if(b == 0) return 1;
    int temp = pow(a , b/2 , m);
    temp = ((temp % m) * (temp % m)) % m;
    if(b & 1) temp = ((temp % m) * (a % m)) % m;
    return temp;
}

inline int add(int a , int b , int m){ return ((a % m) + (b % m)) % m ; }
inline int sub(int a , int b , int m){ return ((a % m) - (b % m) + m) % m ; }
inline int mul(int a , int b , int m){ return ((a % m) * (b % m)) % m ; }
inline int div(int a , int b , int m){ return ((a % m) * (pow(b , m - 2 , m) % m)) % m ; }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
const int MOD = 998244353;
const int mod = 1e9 + 7;
const int N = 1 << 22;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
int dp[N] , arr[(int)1e6];

void solve(){
	int n; cin >> n;
	map<int,int> mp;
	for(int  i = 0 ; i < n ; i++){
		cin >> arr[i];
		mp[arr[i]]++;
	}
	for(int i = 0 ;i < N ; i++){
		if(mp.count(i) > 0){
			dp[i] = i;
		}else{
			dp[i] = -1;
		}
	}
	// for(int i = 0 ; i < 11 ; i++){
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;

	for(int mask = 0 ; mask < N ; mask++){
		for(int i = 0 ; i < 22 ; i++){
			if(((mask >> i)&1) == 0){ // unset hai
				dp[(mask^(1<<i))] = max( dp[mask^(1<<i)] , dp[mask] );
			}
		}
	}
	// for(int i = 0 ; i < 11 ; i++){
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;

	for(int i = 0 ;i  < n  ; i++){
		int temp = arr[i];
		for(int j = 0 ;j  < 22 ; j++){
			if(((arr[i] >> j)&1) == 0){
				// unset
				arr[i] ^= (1<<j);
			}else{
				// already set hai
				arr[i] &= ~(1 << (j));
			}
			// cout << arr[i] << endl;
		}
		cout << dp[arr[i]] << " ";
		// cout << "temp : " << temp << " = > " << arr[i] << "ans : " << dp[arr[i]] << endl;
	}
	cout << endl;

}

int32_t main(){
    letsgo
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin>>t;
    for(int T = 1 ; T <= t ; T++){
    	// cout << "Case #" << T << ": " << endl;
        // clock_t z = clock();
        solve();
        // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
    }
}


// abhishek soni.....[NSIT'22]

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

#define letsgo              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                '\n'
#define ff                  first
#define ss                  second
#define int                 long long
#define ll                  long long
#define mp                  make_pair
#define pb                  push_back
#define pf                  push_front
#define lb                  lower_bound
#define ub                  upper_bound
#define ALL(x)              (x).begin() , (x).end()
#define set_bits(x)         __builtin_popcountll(x)
#define unset_bits(x)       __builtin_ctzll(x)
#define fl(i,a,b)           for(int i = a ; i < b ; i++)
#define bl(i,a,b)           for(int i = a ; i >= b ; i--)

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> pbds;

typedef pair<int,int>                                   pii;
typedef pair<int,pair<int,int>>                         piii;
typedef pair<pair<int,int>,pair<int,int>>               piiii;
typedef priority_queue<int>                             maxpq;
typedef priority_queue<int,vector<int>,greater<int>>    minpq;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int pow(int a,int b,int m){
    if(a == 0) return 0;
    if(b == 0) return 1;
    int temp = pow(a , b/2 , m);
    temp = ((temp % m) * (temp % m)) % m;
    if(b & 1) temp = ((temp % m) * (a % m)) % m;
    return temp;
}

inline int add(int a , int b , int m){ return ((a % m) + (b % m)) % m ; }
inline int sub(int a , int b , int m){ return ((a % m) - (b % m) + m) % m ; }
inline int mul(int a , int b , int m){ return ((a % m) * (b % m)) % m ; }
inline int div(int a , int b , int m){ return ((a % m) * (pow(b , m - 2 , m) % m)) % m ; }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
const int MOD = 998244353;
const int mod = 1e9 + 7;
const int N = 1 << 22;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
int dp[(int)1e8] , arr[(int)1e8];

void solve(){
	int n; cin >> n;
	map<int,int> mp;
	for(int  i = 0 ; i < n ; i++){
		cin >> arr[i];
		mp[arr[i]]++;
	}
	for(int i = 0 ;i < N ; i++){
		if(mp.count(i) > 0){
			dp[i] = i;
		}else{
			dp[i] = -1;
		}
	}
	// for(int i = 0 ; i < 11 ; i++){
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;

	for(int mask = 0 ; mask < N ; mask++){
		for(int i = 0 ; i < 23 ; i++){
			if(((mask >> i)&1) == 0){ // unset hai
				dp[(mask^(1<<i))] = max( dp[mask^(1<<i)] , dp[mask] );
			}
		}
	}
	// for(int i = 0 ; i < 11 ; i++){
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;

	for(int i = 0 ;i  < n  ; i++){
		int temp = arr[i];
		for(int j = 0 ;j  < 23 ; j++){
			if(((arr[i] >> j)&1) == 0){
				// unset
				arr[i] ^= (1<<j);
			}else{
				// already set hai
				arr[i] &= ~(1 << (j));
			}
			// cout << arr[i] << endl;
		}
		cout << dp[arr[i]] << " ";
		// cout << "temp : " << temp << " = > " << arr[i] << "ans : " << dp[arr[i]] << endl;
	}
	cout << endl;

}

int32_t main(){
    letsgo
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin>>t;
    for(int T = 1 ; T <= t ; T++){
    	// cout << "Case #" << T << ": " << endl;
        // clock_t z = clock();
        solve();
        // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
    }
}


// abhishek soni.....[NSIT'22]

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

#define letsgo              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                '\n'
#define ff                  first
#define ss                  second
#define int                 long long
#define ll                  long long
#define mp                  make_pair
#define pb                  push_back
#define pf                  push_front
#define lb                  lower_bound
#define ub                  upper_bound
#define ALL(x)              (x).begin() , (x).end()
#define set_bits(x)         __builtin_popcountll(x)
#define unset_bits(x)       __builtin_ctzll(x)
#define fl(i,a,b)           for(int i = a ; i < b ; i++)
#define bl(i,a,b)           for(int i = a ; i >= b ; i--)

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> pbds;

typedef pair<int,int>                                   pii;
typedef pair<int,pair<int,int>>                         piii;
typedef pair<pair<int,int>,pair<int,int>>               piiii;
typedef priority_queue<int>                             maxpq;
typedef priority_queue<int,vector<int>,greater<int>>    minpq;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int pow(int a,int b,int m){
    if(a == 0) return 0;
    if(b == 0) return 1;
    int temp = pow(a , b/2 , m);
    temp = ((temp % m) * (temp % m)) % m;
    if(b & 1) temp = ((temp % m) * (a % m)) % m;
    return temp;
}

inline int add(int a , int b , int m){ return ((a % m) + (b % m)) % m ; }
inline int sub(int a , int b , int m){ return ((a % m) - (b % m) + m) % m ; }
inline int mul(int a , int b , int m){ return ((a % m) * (b % m)) % m ; }
inline int div(int a , int b , int m){ return ((a % m) * (pow(b , m - 2 , m) % m)) % m ; }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
const int MOD = 998244353;
const int mod = 1e9 + 7;
const int N = 1 << 22;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
int dp[N] , arr[(int)1e6];

void solve(){
	int n; cin >> n;
	memset(dp,-1,sizeof(dp));
	for(int  i = 0 ; i < n ; i++){
		cin >> arr[i];
		dp[arr[i]] = arr[i];
	}
	for(int mask = 0 ; mask < N ; mask++){
		for(int i = 0 ; i < 22 ; i++){
			if(((mask >> i)&1) == 0){ // unset hai
				dp[(mask^(1<<i))] = max( dp[mask^(1<<i)] , dp[mask] );
			}
		}
	}
	for(int i = 0 ;i  < n  ; i++){
		int temp = arr[i];
		for(int j = 0 ;j  < 22 ; j++){
			if(((arr[i] >> j)&1) == 0){
				// unset
				arr[i] ^= (1<<j);
			}else{
				// already set hai
				arr[i] &= ~(1 << (j));
			}
		}
		cout << dp[arr[i]] << " ";
		// cout << "temp : " << temp << " = > " << arr[i] << "ans : " << dp[arr[i]] << endl;
	}
	cout << endl;

}

int32_t main(){
    letsgo
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin>>t;
    for(int T = 1 ; T <= t ; T++){
    	// cout << "Case #" << T << ": " << endl;
        // clock_t z = clock();
        solve();
        // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
    }
}


// abhishek soni.....[NSIT'22]

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

#define letsgo              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                '\n'
#define ff                  first
#define ss                  second
#define int                 long long
#define ll                  long long
#define mp                  make_pair
#define pb                  push_back
#define pf                  push_front
#define lb                  lower_bound
#define ub                  upper_bound
#define ALL(x)              (x).begin() , (x).end()
#define set_bits(x)         __builtin_popcountll(x)
#define unset_bits(x)       __builtin_ctzll(x)
#define fl(i,a,b)           for(int i = a ; i < b ; i++)
#define bl(i,a,b)           for(int i = a ; i >= b ; i--)

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> pbds;

typedef pair<int,int>                                   pii;
typedef pair<int,pair<int,int>>                         piii;
typedef pair<pair<int,int>,pair<int,int>>               piiii;
typedef priority_queue<int>                             maxpq;
typedef priority_queue<int,vector<int>,greater<int>>    minpq;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

int pow(int a,int b,int m){
    if(a == 0) return 0;
    if(b == 0) return 1;
    int temp = pow(a , b/2 , m);
    temp = ((temp % m) * (temp % m)) % m;
    if(b & 1) temp = ((temp % m) * (a % m)) % m;
    return temp;
}

inline int add(int a , int b , int m){ return ((a % m) + (b % m)) % m ; }
inline int sub(int a , int b , int m){ return ((a % m) - (b % m) + m) % m ; }
inline int mul(int a , int b , int m){ return ((a % m) * (b % m)) % m ; }
inline int div(int a , int b , int m){ return ((a % m) * (pow(b , m - 2 , m) % m)) % m ; }

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
const int MOD = 998244353;
const int mod = 1e9 + 7;
const int N = 1 << 22;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
int dp[(1 << (23))] , arr[(int)1e6];

void solve(){
	int n; cin >> n;
	map<int,int> mp;
	for(int  i = 0 ; i < n ; i++){
		cin >> arr[i];
		mp[arr[i]]++;
	}
	for(int i = 0 ;i < N ; i++){
		if(mp.count(i) > 0){
			dp[i] = i;
		}else{
			dp[i] = -1;
		}
	}
	// for(int i = 0 ; i < 11 ; i++){
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;

	for(int mask = 0 ; mask < N ; mask++){
		for(int i = 0 ; i < 23 ; i++){
			if(((mask >> i)&1) == 0){ // unset hai
				dp[(mask^(1<<i))] = max( dp[mask^(1<<i)] , dp[mask] );
			}
		}
	}
	// for(int i = 0 ; i < 11 ; i++){
	// 	cout << dp[i] << " ";
	// }
	// cout << endl;

	for(int i = 0 ;i  < n  ; i++){
		int temp = arr[i];
		for(int j = 0 ;j  < 23 ; j++){
			if(((arr[i] >> j)&1) == 0){
				// unset
				arr[i] ^= (1<<j);
			}else{
				// already set hai
				arr[i] &= ~(1 << (j));
			}
			// cout << arr[i] << endl;
		}
		cout << dp[arr[i]] << " ";
		// cout << "temp : " << temp << " = > " << arr[i] << "ans : " << dp[arr[i]] << endl;
	}
	cout << endl;

}

int32_t main(){
    letsgo
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t = 1;
    // cin>>t;
    for(int T = 1 ; T <= t ; T++){
    	// cout << "Case #" << T << ": " << endl;
        // clock_t z = clock();
        solve();
        // cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);
    }
}