#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define REP(i,n) for(int i=0;i<int(n);i++) int main(void){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll i,j,k; int T; cin >> T; while(T--){ ll x,y; cin >> x >> y; ll p; for(j=y;j<=60;j++){ if((x & (1LL<<j))==0LL){ p=j; break; } } cout << (1LL<<p)-1 << endl; } return 0; }