#include<bits/stdc++.h>

using namespace std;

const int INF = 1LL << 30;

int main()
{
  int T;

  cin >> T;
  while(T--) {
    int N, D;
    cin >> N >> D;

    multiset< int > val;
    val.insert(D);
    for(int i = 0; i < N - 1; i++) {
      int k = *val.begin();
      val.erase(val.begin());
      val.insert(k ^ 127);
      val.insert(127);
    }
    cout << accumulate(begin(val), end(val), 0) << endl;
  }

}
