#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll x, y, c[7];
void solve(){
cin >> x >> y;
for(int i=1;i<=6;i++) cin >> c[i];
ll B=y-x,A=y-B;
ll r1=(A<0?c[4]:c[1])*abs(A)+(B<0?c[5]:c[2])*abs(B);
B=x-y,A=x-B;
ll r2=(A<0?c[4]:c[1])*abs(A)+(B<0?c[3]:c[6])*abs(B);
A=x,B=y;
ll r3=(A<0?c[3]:c[6])*abs(A)+(B<0?c[5]:c[2])*abs(B);
cout<<min({r1,r2,r3});
}
int main()
{
int t;
cin >> t;
while(t--){
solve();
cout << "\n";
}
}
Split houses | Divisible |
Three primes | Coprimes |
Cost of balloons | One String No Trouble |
Help Jarvis! | Lift queries |
Goki and his breakup | Ali and Helping innocent people |
Book of Potion making | Duration |
Birthday Party | e-maze-in |
Bricks Game | Char Sum |
Two Strings | Anagrams |
Prime Number | Lexical Sorting Reloaded |
1514A - Perfectly Imperfect Array | 580A- Kefa and First Steps |
1472B- Fair Division | 996A - Hit the Lottery |
MSNSADM1 Football | MATCHES Playing with Matches |
HRDSEQ Hard Sequence | DRCHEF Doctor Chef |
559. Maximum Depth of N-ary Tree | 821. Shortest Distance to a Character |