#include <iostream>
#include <fstream>
#include <map>
#include <string>
using namespace std;
ifstream fin("bits.in");
ofstream fout("bits.out");
int n, x, biggest;

int main()
{
    fin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> x;
        int j = 0, nrb = 0, rez = 0;
        while( (1 << j) <= x)
        {
            if((1 << j) & x)
                nrb++;
            j++;
        }
        biggest = j - 1;
        while(nrb)
        {
            rez = rez + (1 << biggest);
            biggest--;
            nrb--;
        }
        cout << rez <<endl;
    }
    return 0;
}