#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)


int main(){
	int t;
	cin>>t;
	while(t--){
		int n,d;
		cin>>n>>d;
		
		int res;
		if(n%2==1)res = d;
		else res = d^127;
		
		cout<<127*(n-1)+res<<endl;
	}
}