#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,a,b,c;
while(cin>>n){
while(n--){
int aa[4]={0};
cin>>a>>b>>c;
aa[(a-1)%4]=1;
cout<<aa[0]*(b+c)+aa[1]*(b-c)+aa[2]*(b*c)+aa[3]*(b/c)<<endl;
}
}
return 0;
}