#include using namespace std; constexpr long long inf = 9e18; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int tt; cin >> tt; while (tt--) { long long a, b, c, x, y, z; cin >> a >> b >> c >> x >> y >> z; long long res = inf; for (int _ = 2; _--; ) { if (a >= 2 and c >= 3) { long long crr = max(a - c + 1, 0LL) * x + max(b - min(a, c - 1) + 1, 0LL) * y; res = min(res, crr); } if (a >= 2 and b >= 3) { long long crr = max(a - b + 1, 0LL) * x + max(c - min(a, b - 1) + 1, 0LL) * z; res = min(res, crr); } swap(a, c); swap(x, z); } cout << (res < inf ? res : -1) << '\n'; } }