#include #include #include #include using namespace std; const long long inf = 1LL << 62; bool is_kadomatsu(long long A, long long B, long long C) { return A != B && B != C && C != A && (B == max({ A, B, C }) || B == min({ A, B, C })); } int main() { int Q; cin >> Q; while (Q--) { long long A, B, C, X, Y, Z; cin >> A >> B >> C >> X >> Y >> Z; vector cp; for (long long i = A; i <= A + 3; ++i) cp.push_back(i); for (long long i = B; i <= B + 3; ++i) cp.push_back(i); for (long long i = C; i <= C + 3; ++i) cp.push_back(i); sort(cp.begin(), cp.end()); cp.erase(unique(cp.begin(), cp.end()), cp.end()); long long ans = inf; for (long long i : cp) { for (long long j : cp) { for (long long k : cp) { if (i < A || j < B || k < C) continue; long long ca = i - A, cb = j - B, cc = k - C; long long ra = A - cb - cc, rb = B - cc - ca, rc = C - ca - cb; if (ra > 0 && rb > 0 && rc > 0 && is_kadomatsu(ra, rb, rc)) { ans = min(ans, cc * X + ca * Y + cb * Z); } } } } cout << (ans != inf ? ans : -1) << '\n'; } return 0; }