#include using namespace std; int64_t solve(int64_t a, int64_t b, int64_t c, int64_t x, int64_t y, int64_t z) { int64_t ans = 0; if (a > c) { swap(a, c); swap(x, z); } if (a == c) { if (x > z) swap(x, z); a--; ans += x; } if (a == 0) return -1; if (a > b || b > c) return ans; if (a == 1) { if (b <= 2) { return -1; } else { return ans + (c - b + 1) * z; } } if (c - a == 1) { int64_t aminus = x + solve(a - 1, b, c, x, y, z); if (aminus == x - 1) return ans + (b - a + 1) * y; return ans + min((b - a + 1) * y, aminus); } if (b - a == 1) { int64_t aminus = x + solve(a - 1, b, c, x, y, z); if (aminus == x - 1) return ans + min((b - a + 1) * y, (c - a + 1) * z); return ans + min(aminus, min((b - a + 1) * y, (c - a + 1) * z)); } return ans + min((b - a + 1) * y, (c - b + 1) * z); } int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int64_t a, b, c, x, y, z; cin >> a >> b >> c >> x >> y >> z; cout << solve(a, b, c, x, y, z) << endl; } }