#include<bits/stdc++.h>

using namespace std;


int getBigger(int n){

    if( n == 0 ) return 0;
    
  int leftmost=0,rightmost=0,zero=0;
  int zeropos=-1;
  while(n>=(1<<leftmost)){
    leftmost++;
  }
  while(zero < leftmost && zero <=31){
    if(!(n & (1<<zero))){
      zeropos = zero;
    }
    zero++;
  }
  while(!(n&(1<<rightmost))){
    rightmost++;
  }
  if(zeropos > rightmost){
    n|=(1<<zeropos);
    n&=(~(1<<rightmost));
  }
  return n;
}

int main(){

  int n,x;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> x;
    cout << getBigger(x) << '\n';
  }

  return 0;
}