#include <bits/stdc++.h>
using namespace std;
const int nax = 1e9 + 7;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const long long infll = 1e18 + 7;
const long double PI = 3.1415926535897932384626433832795;
void solve() {
  long long x, y;
  long long c[6];
  cin >> y >> x;
  for (int i = 0; i < 6; ++i) {
    cin >> c[i];
  }
  long long ans = infll;
  if (x >= 0 && y >= 0) {
    ans = x * c[1] + y * c[5];
    if (x > y) {
      ans = min(ans, y * c[0] + (x - y) * c[1]);
      ans = min(ans, x * c[0] + (x - y) * c[2]);
    } else {
      ans = min(ans, x * c[0] + (y - x) * c[5]);
      ans = min(ans, y * c[0] + (y - x) * c[4]);
    }
  } else if (x < 0 && y >= 0) {
    x = -x;
    ans = x * c[4] + y * c[5];
    ans = min(ans, (x + y) * c[4] + y * c[0]);
    ans = min(ans, (x + y) * c[5] + x * c[3]);
  } else if (x < 0 && y < 0) {
    x = -x, y = -y;
    ans = x * c[4] + y * c[2];
    if (x > y) {
      ans = min(ans, (x - y) * c[4] + y * c[3]);
      ans = min(ans, x * c[3] + (x - y) * c[5]);
    } else {
      ans = min(ans, (y - x) * c[2] + x * c[3]);
      ans = min(ans, y * c[3] + (y - x) * c[1]);
    }
  } else if (x >= 0 && y < 0) {
    y = -y;
    ans = x * c[1] + y * c[2];
    ans = min(ans, x * c[0] + (x + y) * c[2]);
    ans = min(ans, y * c[3] + (x + y) * c[1]);
  } else {
  }
  printf("%lld\n", ans);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
