#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 100500;
int main() {
  int T;
  cin >> T;
  while (T--) {
    long long x, y;
    cin >> x >> y;
    swap(x, y);
    long long c[7];
    for (int i = 1; i <= 6; i++) cin >> c[i];
    for (int it = 1; it <= 6; it++) {
      for (int i = 1; i <= 6; i++) {
        int prv = (i == 1 ? 6 : i - 1);
        int nxt = (i == 6 ? 1 : i + 1);
        c[i] = min(c[i], c[prv] + c[nxt]);
      }
    }
    if (x <= 0 && y >= 0)
      cout << (-x) * c[5] + y * c[6] << "\n";
    else if (x >= 0 && y <= 0)
      cout << x * c[2] + (-y) * c[3] << "\n";
    else if (x >= 0 && y >= 0)
      cout << min(min(x, y) * c[1] + (x - min(x, y)) * c[2] +
                      (y - min(x, y)) * c[6],
                  x * c[2] + y * c[6])
           << "\n";
    else {
      x = -x, y = -y;
      cout << min(min(x, y) * c[4] + (x - min(x, y)) * c[5] +
                      (y - min(x, y)) * c[3],
                  x * c[5] + y * c[3])
           << "\n";
    }
  }
  return 0;
}
