#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

int main()
{
    int n;
    int number;
    cin>> n;

    while(n--)
    {
        cin>>number;
        if( number == 0 || number == 1 )
        {
            cout<< number<<" ";
            continue;
        }

        bitset<32> binaryNumber(number);
        int indexMostSegnificantBit = 0;

        for( int index = 0; index < 32; ++index )
            if( binaryNumber[index] )
                indexMostSegnificantBit = index;

        int countFlip = 0;
        for( int index = indexMostSegnificantBit; index >= 0 && countFlip < 2; --index )
            if( !binaryNumber[index] )
            {
                binaryNumber[index].flip();
                ++countFlip;
            }
        for( int index = 0; index < 32 && countFlip < 2; ++index, ++countFlip  )
            binaryNumber[index].flip();

        int numberAux = binaryNumber.to_ulong();

        cout<< max(number, numberAux)<<" ";
    }

    return 0;
}