// mc2a.cpp : Defines the entry point for the console application.
//

#include <iostream>
using namespace std;

long long i, n, a, j;
int main()
{
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a;
        long long maxi = -1, maxb = -1;
        for (j = 0; j <= 31; j++)
        {
            if (a <= (1LL << (j)))
            {
                break;
            }
            if ((a & (1LL<<j)) != 0 && maxi == -1)
            {
                maxi = j;
            }
            if ((a & (1LL << j)) == 0)
            {
                maxb = j;
            }
        }
        
        if (maxi != -1 && maxb != -1 && maxi < maxb)
        {
            cout << a - (1LL << maxi) + (1LL << maxb);
        }
        else
            cout << a;
        cout << " ";

    }

}