#include <bits/stdc++.h>
using namespace std;
#define user333 meow

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        int g, a, h, w;
        cin >> g >> a >> h >> w;
        cout << fixed << setprecision(2) << (g == 1 ? 13.7 * w + 5.0 * h - 6.8 * a + 66 : 9.6 * w + 1.8 * h - 4.7 * a + 655) << '\n';
    }
}