#include using namespace std; using ll=long long; ll msb(ll x){ return (63-__builtin_clzll(x)); } ll est(ll r,ll c){ for(ll i=msb(r);i>=0;i--){ if((r&(1ll<; int dx8[8]={-1,-1,-1,0,0,1,1,1}; int dy8[8]={-1,0,1,-1,1,-1,0,1}; bool ok(int r,int c){ if(r<1 || c<1){return false;} if(r&(1<<(c-1))){return true;} return false; } // int main(){ // vector> dp(5000,vector(100,1e9)); // queue q; // q.push({1,1}); // dp[1][1]=0; // while(!q.empty()){ // auto od=q.front(); q.pop(); // for(int k=0;k<8;k++){ // int x=od.first+dx8[k]; // int y=od.second+dy8[k]; // if(!ok(x,y)){continue;} // if(x>=5000){continue;} // if(y>=100){continue;} // if(dp[x][y]>5e8){ // dp[x][y]=dp[od.first][od.second]+1; // q.push({x,y}); // } // } // } // for(int i=0;i<4096;i++){ // for(int j=0;j<20;j++){ // if(dp[i][j]>5e8){ // continue; // } // else{ // if(dp[i][j]!=est(i,j)){ // cout << i << " " << j << " "; // cout << dp[i][j] << " " << est(i,j) << "\n"; // } // } // } // } // // for(int i=0;i<60;i++){ // // for(int j=0;j<20;j++){ // // if(dp[i][j]>5e8){ // // printf("-- "); // // } // // else{ // // printf("%2d ",dp[i][j]); // // } // // } // // printf("\n"); // // } // return 0; // } int main(){ int t; cin >> t; while(t--){ ll r,c; cin >> r >> c; cout << est(r,c) << "\n"; } }