#include <bits/stdc++.h>
#define LL long long
#define PB push_back
#define INF 1000 * 1000 * 1000
#define X first
#define Y second
#define x first
#define y second
#define pt pair<int , int> 
using namespace std;
const int mod = 998244353;


int main()
{
	ios_base::sync_with_stdio(0);
	int T;
	cin >> T;
	while(T--)
	{
		int N , D;
		cin >> N >> D;
		int ans = (N - 1) * 127;
		if(!(N % 2))
			D ^= 127;
		cout << ans + D << endl;
	}
}

