#include <bits/stdc++.h>

using namespace std;
long q,n,d;
int a[8];
void np(long & n,long i)
{
    if(n>=pow(2,i-1)) {
        a[i]=1;
        n=n-pow(2,i);
    }
    else a[i]=0;
}
int main()
{
    cin>>q;
    while(q--)
    {
        cin>>n>>d;
        if(n%2==1) cout<<(n-1)*127+d;
        else{
        long cc=(d^127);
        cout<<(n-1)*127+cc;

    }
    cout<<endl;
    }



}
