#include<iostream>
using namespace std;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int num,c,sum=0;
		scanf("%d %d",&num,&c);num--;
		int y = 127-c;
		sum = 127 * num;
		if(num%2 == 0){
			sum+=c;
		}else{
			sum+=y;
		}
		printf("%d\n",sum);
	}
	return 0;
}