#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch&15);ch=getchar();}
	if(f) return x;else return -x;
}
int t;
int main(){
	t=read();
	while(t--){
		int n=read(),d=read();
		if(n%2) printf("%d\n",(n-1)*127+d);
		else printf("%d\n",n*127-d);
	}
	return 0;
} 