#include #include using namespace std; int N,c[60]; long X; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T;cin>>T; for(;T--;) { cin>>N>>X; for(int i=0;i>c[i]; int i=N-1; while(i>=0&&(X>>c[i]&1))i--; if(i<0) { cout<<"0\n"; continue; } const long t=1L<>c[i]) { ans=min(ans,(X-(X/t*t-1))*2); } cout<