#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
std::ifstream ___in("input.in");
using namespace std;
using ll = long long;
static const bool tc = 1;
static const ll mod = LLONG_MAX - 24;
void solve() {
  ll x, y, c[7];
  cin >> x >> y;
  for (int i = 1; i <= 6; ++i) cin >> c[i];
  vector<ll> plusX, plusY, minX, minY, minXY, plusXY;
  plusX.push_back(c[6]);
  plusX.push_back(c[1] + c[5]);
  plusY.push_back(c[2]);
  plusY.push_back(c[1] + c[3]);
  minX.push_back(c[3]);
  minX.push_back(c[4] + c[2]);
  minY.push_back(c[5]);
  minY.push_back(c[4] + c[6]);
  plusXY.push_back(c[1]);
  plusXY.push_back(c[6] + c[2]);
  minXY.push_back(c[4]);
  minXY.push_back(c[3] + c[5]);
  sort(plusX.begin(), plusX.end());
  sort(plusY.begin(), plusY.end());
  sort(minX.begin(), minX.end());
  sort(minY.begin(), minY.end());
  sort(minXY.begin(), minXY.end());
  sort(plusXY.begin(), plusXY.end());
  if (x == 0 && y == 0) {
    cout << 0 << "\n";
    return;
  }
  if (x == 0) {
    if (y > 0)
      cout << plusY[0] * y << "\n";
    else
      cout << minY[0] * (-y) << "\n";
    return;
  }
  if (y == 0) {
    if (x > 0)
      cout << plusX[0] * x << "\n";
    else
      cout << minX[0] * (-x) << "\n";
    return;
  }
  ll ans = mod;
  if (x > 0 && y > 0) {
    ans = min(ans, min(min(x, y) * plusXY[0] + (x - min(x, y)) * plusX[0] +
                           (y - min(x, y)) * plusY[0],
                       x * plusX[0] + y * plusY[0]));
  }
  if (x < 0 && y < 0) {
    ans = min(ans, min(-max(x, y) * minXY[0] - (x - max(x, y)) * minX[0] -
                           (y - max(x, y)) * minY[0],
                       -x * minX[0] - y * minY[0]));
  }
  if (x < 0 && y > 0) {
    ans = min(ans, -x * minX[0] + y * plusY[0]);
  }
  if (x > 0 && y < 0) {
    ans = min(ans, x * plusX[0] - y * minY[0]);
  }
  cout << ans << "\n";
}
int main() {
  srand(time(0));
  int T = 1;
  if (tc) cin >> T;
  for (int i = 1; i <= T; ++i) {
    solve();
  }
  return 0;
}
