#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<ll, ll> II;
typedef vector<II> vi;

int main()
{
    int t, n, d;
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> t;
    while (t--) {
        cin >> n >> d;
        int p = n-1;
        if (p % 2 == 0) cout << d + 127*p;
        else cout << (127^d) + 127*p;
        cout << endl;
    }
    return 0;
}
