#include <bits/stdc++.h>
using namespace std;

int main()
{
	int T, N, D;
	cin >> T;
	while (T--) {
		cin >> N >> D;
		if (N & 1)
			cout << 127 * (N - 1) + D << endl;
		else
			cout << 127 * (N - 1) + (D ^ 127) << endl;
	}
	return 0;
}
