#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int n,g,a,h,w;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>g>>a>>h>>w;
double BMR;
if(g==1)
BMR=13.7*w+5*h-6.8*a+66;
else
BMR=9.6*w+1.8*h-4.7*a+655;
printf("%.2f\n",BMR);
}
}