#include using namespace std; typedef long long ll; typedef pair P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto&(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) void solve() { vector a(3), c(3); REP(i, 3) { cin >> a[i]; } REP(i, 3) { cin >> c[i]; } ll ans = 1e18; if (a[0] == a[1] && a[1] == a[2]) { // 1 1 1 -> -1 // 2 2 2 -> -1 if (a[0] <= 2) { cout << -1 << endl; return; } // 3 3 3 -> 3 cout << min(c[0] + 2 * c[2], c[2] + 2 * c[0]) << endl; return; } // 両側2つ等しい // 2 1 2 -> -1 // 1 2 1 -> -1 if (a[0] == 1 && a[1] >= 2 && a[2] == 1 || a[0] == 2 && a[1] == 1 && a[2] == 2) { cout << -1 << endl; return; } if (a[0] == a[2]) { if (a[0] == a[1] + 1) { // 4 3 4 -> 2 cout << 2 * min(c[0], c[2]) << endl; return; } // 6 3 6 -> 1 // 3 4 3 -> 1 cout << min(c[0], c[2]) << endl; return; } ll mini = 1e18, maxi = -1; ll idxmin, idxmax; REP(i, 3) { mini = min(mini, a[i]); if (mini == a[i]) { idxmin = i; } maxi = max(maxi, a[i]); if (maxi == a[i]) { idxmax = i; } } // 1 1 6 -> -1 if (a[0] == a[1] && a[0] == 1 || a[1] == a[2] && a[2] == 1) { cout << -1 << endl; return; } // 2 2 1 -> -1 // 1 2 2 -> -1 if (a[1] == 2 && (a[0] == 2 && a[2] == 1 || a[0] == 1 && a[2] == 2)) { cout << -1 << endl; return; } // 3 3 2 -> 2 if (a[0] == a[1] && a[1] - 1 == a[2]) { cout << 2 * min(c[0], c[1]) << endl; return; } // 2 3 3 -> 2 if (a[1] == a[2] && a[1] - 1 == a[0]) { cout << 2 * min(c[2], c[1]) << endl; return; } // 3 3 1 if (a[0] == a[1]) { cout << min(c[0], c[1]) << endl; return; } // 1 3 3 if (a[1] == a[2]) { cout << min(c[1], c[2]) << endl; return; } // 全部異なる // 1 4 3 // 4 2 3 if (a[1] > a[0] && a[1] > a[2] || a[1] < a[0] && a[1] < a[2]) { cout << 0 << endl; return; } if (mini == 1) { if (a[1] == 2) { cout << -1 << endl; return; } cout << c[idxmax] * (maxi - a[1] + 1) << endl; return; } cout << min(c[idxmin] * (a[1] - mini + 1), c[idxmax] * (maxi - a[1] + 1)) << endl; } int main() { ll n; cin >> n; while (n--) solve(); }