#include using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; const static ll INF = (ll)(1e15); bool isKadomatsu(int A, int B, int C){ map m; m[A] = 1; m[B] = 1; m[C] = 1; if(m.size() != 3) return false; vector v{A,B,C}; sort(ALLOF(v)); return (v[1]==A || v[1]==C); } ll check(int A, int B, int C, int tA, int tB, int tC, int X, int Y, int Z){ if(!isKadomatsu(tA, tB, tC)) return INF; ll ret = 0; ret += (A-tA) * (ll)X; ret += (B-tB) * (ll)Y; ret += (C-tC) * (ll)Z; return ret; } ll solve(int A, int B, int C, int X, int Y, int Z){ map cand; for(int i=-2; i<=2; i++) if(A+i>0) cand[A+i] = 1; for(int i=-2; i<=2; i++) if(B+i>0) cand[B+i] = 1; for(int i=-2; i<=2; i++) if(C+i>0) cand[C+i] = 1; vector v; FOR(it,cand) v.push_back(it->first); ll ret = INF; rep(i,v.size()){ if(A> T; rep(t,T){ int A, B, C, X, Y, Z; cin >> A >> B >> C >> X >> Y >> Z; cout << solve(A, B, C, X, Y, Z) << endl; } return 0; }