#include <bits/stdc++.h>
using namespace std;
long long int pow_mod(long long int a, long long int b) {
  long long int res = 1;
  while (b != 0) {
    if (b & 1) {
      res = (res * a) % 998244353;
    }
    a = (a * a) % 998244353;
    b /= 2;
  }
  return res;
}
long long int inv_mod(long long int x) { return pow_mod(x, 998244353 - 2); }
const long long int N = (long long int)3e5;
long long int inv[N];
long long int fac[N];
void init() {
  fac[0] = 1;
  for (long long int i = 1; i < N; i++) fac[i] = (i * fac[i - 1]) % 998244353;
  for (long long int i = 0; i < N; i++) inv[i] = inv_mod(fac[i]);
}
long long int ncr(long long int n, long long int r) {
  if (n < r) return 0;
  if (n == r || r == 0) return 1LL;
  long long int x = fac[n];
  long long int y = inv[n - r];
  long long int z = inv[r];
  return ((x * y) % 998244353 * z) % 998244353;
}
void solve() {
  long long int x_cor;
  long long int y_cor;
  cin >> x_cor >> y_cor;
  long long int c[6];
  for (long long int i = 0; i < 6; i++) cin >> c[i];
  long long int ans = 0;
  ans = (long long int)6e18;
  if (x_cor == y_cor) {
    if (x_cor < 0)
      ans = x_cor * c[3];
    else
      ans = x_cor * c[0];
    ans = abs(ans);
  } else if (x_cor == 0) {
    if (y_cor > 0) {
      ans = y_cor * c[1];
    } else {
      ans = y_cor * c[4];
    }
    ans = abs(ans);
  } else if (y_cor == 0) {
    if (x_cor > 0) {
      ans = x_cor * c[5];
    } else
      ans = x_cor * c[2];
    ans = abs(ans);
  }
  long long int dirx[6];
  long long int diry[6];
  dirx[0] = diry[0] = 1;
  dirx[1] = 0;
  diry[1] = 1;
  dirx[2] = -1;
  diry[2] = 0;
  dirx[3] = diry[3] = -1;
  dirx[4] = 0;
  diry[4] = -1;
  dirx[5] = 1;
  diry[5] = 0;
  for (long long int i = 0; i < 6; i++) {
    for (long long int j = 0; j < 6; j++) {
      if (dirx[i] + dirx[j] == 0 && diry[i] + diry[j] == 0) continue;
      if (i == j) continue;
      if (dirx[i] * diry[j] - diry[i] * dirx[j] == 0) continue;
      long long int b = y_cor * dirx[i] - x_cor * diry[i];
      b /= (dirx[i] * diry[j] - diry[i] * dirx[j]);
      long long int a = x_cor - b * dirx[j];
      if (dirx[i] == 0) continue;
      a /= dirx[i];
      if (a > 0 && b > 0) ans = min(ans, a * c[i] + b * c[j]);
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
