#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

int MAIN()
{
	int T;
	cin >> T;
	while(T--)
	{
		int n, x;
		cin >> n >> x;
		int curXor = 0;
		if(n % 2 == 1) curXor = 127;
		int needModify = curXor ^ x;
		int lastNum = 127 ^ needModify;
		cout << (n - 1) * 127 + lastNum << endl;
	}
	return 0;
}

int main()
{
	int start = clock();
	#ifdef LOCAL_TEST
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios :: sync_with_stdio(false);
	cout << fixed << setprecision(16);
	int ret = MAIN();
	#ifdef LOCAL_TEST
		cout << "[Finished in " << clock() - start << " ms]" << endl;
	#endif
	return ret;
}
