#include <bits/stdc++.h>
using namespace std;
long long absc(long long a) {
  if (a < 0) {
    return -a;
  } else {
    return a;
  }
}
void solve() {
  long long x, y, c[7], ans = 0;
  int i;
  cin >> x >> y;
  for (i = 1; i <= 6; i++) cin >> c[i];
  for (int k = 1; k <= 100; k++) {
    c[2] = min(c[1] + c[3], c[2]);
    c[3] = min(c[2] + c[4], c[3]);
    c[4] = min(c[3] + c[5], c[4]);
    c[5] = min(c[4] + c[6], c[5]);
    c[6] = min(c[5] + c[1], c[6]);
    c[1] = min(c[2] + c[6], c[1]);
  }
  if (x == 0) {
    cout << abs(y) * (y < 0 ? c[5] : c[2]) << "\n";
    return;
  }
  if (y == 0) {
    cout << abs(x) * (x < 0 ? c[3] : c[6]) << "\n";
    return;
  }
  if (x < 0) {
    int mn = min(abs(x), abs(y));
    if (y < 0) {
      ans = c[4] * mn;
      x += mn;
      y += mn;
    }
    ans += abs(x) * c[3] + abs(y) * ((y > 0) ? c[2] : c[5]);
  }
  if (x > 0) {
    int mn = min(x, abs(y));
    if (y > 0) {
      ans = c[1] * mn;
      x -= mn;
      y -= mn;
    }
    ans += x * c[6] + abs(y) * ((y > 0) ? c[2] : c[5]);
  }
  cout << ans << "\n";
}
int main() {
  long long T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}
