#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int T; cin >> T;
    while (T--) {
        int N, D; cin >> N >> D;
        if (N % 2 == 0) D ^= 127;
        cout << 127 * (N - 1) + D << '\n';
    }
    return 0;
}