/* -*- coding: utf-8 -*- * * 3288.cc: No.3288 Sloppy Land Grading - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 100000; const long long LINF = 1LL << 62; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N]; /* subroutines */ ll calc(int a, int b, int c, int x, int y, int z, int d) { return (ll)abs(a - d) * x + (ll)abs(b - d) * y + (ll)abs(c - d) * z; } /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int a, b, c, x, y, z; scanf("%d%d%d%d%d%d", &a, &b, &c, &x, &y, &z); int d0 = min(min(a, b), c); int d1 = max(max(a, b), c); while (d0 + 2 <= d1) { int dd0 = (d0 * 2 + d1) / 3; int dd1 = (d0 + d1 * 2) / 3; ll s0 = calc(a, b, c, x, y, z, dd0); ll s1 = calc(a, b, c, x, y, z, dd1); if (s0 > s1) d0 = dd0; else d1 = dd1; } ll mins = LINF; for (int d = d0; d <= d1; d++) mins = min(mins, calc(a, b, c, x, y, z, d)); printf("%lld\n", mins); } return 0; }