#include #include #include #define llint long long #define inf 1e18 using namespace std; llint T; llint a, b, c, x, y, z; llint calc(llint a, llint b, llint c) { //cout<< a << " " << b << " " << c << endl; if(a == b && b == c){ if(a <= 2) return inf; llint ans = 2*y+min(x, z); ans = min(ans, x+z+min(x, z)); return ans; } if(a == b){ llint ans = inf; if(a > 1) ans = min(ans, calc(a-1, b, c)+x); if(b > 1) ans = min(ans, calc(a, b-1, c)+y); return ans; } if(b == c){ llint ans = inf; if(b > 1) ans = min(ans, calc(a, b-1, c)+y); if(c > 1) ans = min(ans, calc(a, b, c-1)+z); return ans; } if(a == c){ llint ans = inf; if(a > 1) ans = min(ans, calc(a-1, b, c)+x); if(c > 1) ans = min(ans, calc(a, b, c-1)+z); return ans; } if(a < b){ if(b > c) return 0; llint ans = inf; ans = (c-b+1)*z; if(a == b-1){ if(a == 1) ans = inf; else ans += min(x, z); } if(a > 1) ans = min(ans, (b-a+1)*y); //cout<< a << " " << b << " " << c << " " << ans << endl; return ans; } else{ if(b < c) return 0; llint ans = inf; ans = (a-b+1)*x; if(c == b-1){ if(c == 1) ans = inf; else ans += min(x, z); } if(c > 1) ans = min(ans, (b-c+1)*y); //cout<< a << " " << b << " " << c << " " << ans << endl; return ans; } } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> T; for(int t = 0; t < T; t++){ cin >> a >> b >> c >> x >> y >> z; llint ans = calc(a, b, c); if(ans > inf/2) ans = -1; cout << ans << endl; } return 0; }