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