#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

int solve(int N, int K) {
	vector<int>P(N);
	rep(i, N)P[i] = i;
	int ans = 0;
	do {
		int flag = 1;
		rep(i, N)if (abs(P[i] - i) == K) { flag = 0; break; }
		ans += flag;
		ans %= 924844033;

	} while (next_permutation(ALL(P)));
	return ans;
}

signed main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);

	
	int T;
	cin >> T;
	rep(t, T) {
		int N, D;
		cin >> N >> D;
		cout << (N - 1) * 127 + (N % 2 ? D : (D ^ 127)) << endl;
	}
}