#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) #define revrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--) #define debug(x) cerr << #x << ": " << x << "\n" #define popcnt(x) __builtin_popcount(x) using ll = long long; using P = pair; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template istream& operator >>(istream &is, vector &v) { for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i); return is; } template ostream& operator <<(ostream &os, pair p) { cout << '(' << p.first << ", " << p.second << ')'; return os; } template void print(const vector &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; } template void print(const vector> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); } int main() { int t; cin >> t; const ll INF = 1e18; rep(_t, t) { ll h[3], c[3]; rep(i, 3) cin >> h[i]; rep(i, 3) cin >> c[i]; auto cost = [&](int r1, int r2, int r3){ ll nh1 = h[r1]; ll nh2 = min(h[r2], nh1 - 1); ll nh3 = min(h[r3], nh2 - 1); if (nh3 <= 0) return INF; return (h[r2] - nh2) * c[r2] + (h[r3] - nh3) * c[r3]; }; ll min_cost = min({cost(0, 2, 1), cost(1, 0, 2), cost(1, 2, 0), cost(2, 0, 1)}); if (min_cost != INF) cout << min_cost << endl; else cout << -1 << endl; } }