#include <bits/stdc++.h>
using namespace std;
long long get(long long a, long long b, pair<int, int> i, pair<int, int> j,
              long long pi, long long pj) {
  b -= i.second * abs(a);
  if ((j.second < 0 ? -1 : j.second > 0) == (b < 0 ? -1 : b > 0) || b == 0)
    return abs(a) * pi + abs(b) * pj;
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pair<int, int> delta[6] = {{1, 1},   {0, 1},  {-1, 0},
                             {-1, -1}, {0, -1}, {1, 0}};
  int t, c[6], x, y;
  cin >> t;
  while (t--) {
    cin >> x >> y;
    for (int i = 0; i < 6; ++i) cin >> c[i];
    long long ans = LLONG_MAX;
    for (int i = 0; i < 6; ++i) {
      for (int j = 0; j < 6; ++j) {
        long long got1 = -1, got2 = -1, got3 = -1, got4 = -1;
        if (delta[i].first == 0 &&
            (delta[j].first < 0 ? -1 : delta[j].first > 0) ==
                (x < 0 ? -1 : x > 0))
          got1 = get(x, y, delta[j], delta[i], c[j], c[i]);
        if (delta[j].first == 0 &&
            (delta[i].first < 0 ? -1 : delta[i].first > 0) ==
                (x < 0 ? -1 : x > 0))
          got2 = get(x, y, delta[i], delta[j], c[i], c[j]);
        if (delta[i].second == 0 &&
            (delta[j].second < 0 ? -1 : delta[j].second > 0) ==
                (y < 0 ? -1 : y > 0))
          got3 = get(y, x, {delta[j].second, delta[j].first},
                     {delta[i].second, delta[i].first}, c[j], c[i]);
        if (delta[j].second == 0 &&
            (delta[i].second < 0 ? -1 : delta[i].second > 0) ==
                (y < 0 ? -1 : y > 0))
          got4 = get(y, x, {delta[i].second, delta[i].first},
                     {delta[j].second, delta[j].first}, c[i], c[j]);
        if (got1 != -1) ans = min(ans, got1);
        if (got2 != -1) ans = min(ans, got2);
        if (got3 != -1) ans = min(ans, got3);
        if (got4 != -1) ans = min(ans, got4);
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
