#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll c[10];
int dx[] = {1, 0, -1, -1, 0, 1};
int dy[] = {1, 1, 0, -1, -1, 0};
int main() {
  int t;
  cin >> t;
  while (t--) {
    ll x, y;
    cin >> x >> y;
    for (int i = 0; i < 6; ++i) cin >> c[i];
    long long ans = 5e18;
    auto sign = [](long long x) {
      if (x == 0) return 0;
      if (x < 0) return -1;
      return 1;
    };
    for (int i = 0; i < 6; ++i) {
      for (int j = i; j < 6; ++j) {
        int det = dx[i] * dy[j] - dx[j] * dy[i];
        assert(abs(det) <= 1);
        if (det != 0) {
          long long t1 = x * dy[j] - y * dx[j];
          long long t2 = dx[i] * y - dy[i] * x;
          t1 /= det;
          t2 /= det;
          if (t1 >= 0 && t2 >= 0) {
            ans = min(ans, abs(t1) * c[i] + abs(t2) * c[j]);
          }
        } else {
          if (sign(x) == dx[i] && sign(y) == dy[i]) {
            long long res = 0;
            if (dx[i] != 0)
              res += abs(x) * c[i];
            else if (dy[i] != 0)
              res += abs(y) * c[i];
            if (x == 0 || y == 0 || x == y) {
              ans = min(ans, res);
            }
          }
          if (sign(x) == dx[j] && sign(y) == dy[j]) {
            long long res = 0;
            if (dx[j] != 0)
              res += abs(x) * c[j];
            else if (dy[j] != 0)
              res += abs(y) * c[j];
            if (x == 0 || y == 0 || x == y) {
              ans = min(ans, res);
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
