#include using namespace std; int64_t eval(vector b) { int64_t ans = 0; reverse(b.begin(), b.end()); for(int64_t i = 0; i < int64_t(b.size()); ++i) ans = 2 * ans + b[i]; return ans; } int64_t best(int64_t x) { vector bits; int64_t ans = x; int64_t tmp = x; while(tmp) { bits.push_back(tmp % 2); tmp /= 2; } for(int64_t i = 0; i < int64_t(bits.size()) - 1; ++i) for(int64_t j = i + 1; j < int64_t(bits.size()) - 1; ++j) { swap(bits[i], bits[j]); int64_t e = eval(bits); ans = max(ans, e); swap(bits[i], bits[j]); } return ans; } int main() { int64_t n; cin >> n; for(int64_t i = 0; i < n; ++i) { int64_t x; cin >> x; cout << best(x) << "\n"; } }