#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ui = unsigned int;
const ll amn = 1e6 + 5, mod = 1e9 + 7, an = 1e3 + 5;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll n, m;
ll c[10];
ll cal(ll x, ll a, ll b) {
  if (x >= 0)
    return x * a;
  else
    return -x * b;
}
int main() {
  int T = 1;
  cin >> T;
  while (T--) {
    ll x, y;
    cin >> x >> y;
    for (ll i = 1; i <= 6; i++) cin >> c[i];
    ll ans = 9e18;
    ans = min(ans, cal(x, c[6], c[3]) + cal(y, c[2], c[5]));
    ans = min(ans, cal(x - y, c[6], c[3]) + cal(y, c[1], c[4]));
    ans = min(ans, cal(x, c[1], c[4]) + cal(y - x, c[2], c[5]));
    cout << ans << endl;
  }
}
