#include <bits/stdc++.h>
using namespace std;
#define INF 10001
int ans=0;
int main()
{
	int tc;
	scanf("%d",&tc);
	while(tc--)
	{
		int n,awal,ans;
		cin>>n>>awal;
		if(n%2==1)
			ans=(n-1)*127+awal;
		else
			ans=(n-1)*127+(127^awal);
		cout<<ans<<endl;
	}
}