#include using namespace std ; int main() { // freopen ("input", "r", stdin) ; // freopen ("output", "w", stdout) ; int n ; cin >> n ; while (n --) { int x ; cin >> x ; int put = 0 ; int cop = x ; while (cop) { cop >>= 1 ; put += 1 ; } put -- ; if (put == -1) { cout << x << ' ' ; continue ; } int bit ; for (bit = put ; bit >= 0; bit --) { if (x & (1LL << bit)) { continue ; } else { break ; } } if (bit == -1) { cout << x << ' ' ; continue ; } int bit2 = 0 ; for (bit2 = 0 ; bit2 <= put; ++ bit2) { if (x & (1LL << bit2)) { break ; } else { continue ; } } if (bit2 == put + 1) { cout << x << ' ' ; continue ; } if (bit2 <= bit) { x -= (1LL << bit2) ; x += (1LL << bit) ; } cout << x << ' ' ; } return 0 ; }