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