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

int main() {
    ios::sync_with_stdio(false);
    int nt; cin >> nt;
    for (int tc = 0; tc < nt; ++tc) {
        int n, d; cin >> n >> d;
        cout << (n % 2 == 0 ? d ^ 127 : d) + (n - 1) * 127 << endl;
    }
    return 0;
}
