#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 >> z >> x >> y; long long res = inf; for (int _ = 2; _--; ) { { long long ca = max(a - c + 1, 0LL), cb = max(b - min(a, c - 1) + 1, 0LL); long long crr = ca * x + cb * y; if (a + ca - (ca + cb) > 0 and b + cb - (ca + cb) > 0 and c - (ca + cb) > 0) { res = min(res, crr); } } { long long ca = max(a - b + 1, 0LL), cc = max(c - min(a, b - 1) + 1, 0LL); long long crr = ca * x + cc * z; if (a + ca - (ca + cc) > 0 and c + cc - (ca + cc) > 0 and b - (ca + cc) > 0) { res = min(res, crr); } } swap(a, c); swap(x, z); } cout << (res < inf ? res : -1) << '\n'; } }