#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
template <typename First, typename... Strings>
void print(First arg, const Strings&... rest) {
  cout << arg << " ";
  print(rest...);
}
template <typename First>
void print_vec(vector<First>& v) {
  for (First x : v) cout << x << " ";
  cout << endl;
}
void test_case() {
  long long int a, b;
  cin >> a >> b;
  vector<long long int> c(6);
  for (long long int i = 0; i < 6; i++) cin >> c[i];
  long long int u, d, l, r;
  u = min(c[5], c[4] + c[0]);
  d = min(c[2], c[3] + c[1]);
  l = min(c[4], c[5] + c[3]);
  r = min(c[1], c[0] + c[2]);
  long long int res = 0;
  if (a < 0)
    res += (-a) * d;
  else
    res += (a)*u;
  if (b < 0)
    res += (-b) * l;
  else
    res += (b)*r;
  if (a > 0 && b > 0)
    res =
        min(res, min(a, b) * c[0] + (a - min(a, b)) * u + (b - min(a, b)) * r);
  if (a < 0 && b < 0)
    res = min(res,
              -(max(a, b) * c[3] + (a - max(a, b)) * d + (b - max(a, b)) * l));
  print(res);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  for (long long int i = 0; i < t; i++) {
    test_case();
  }
  return 0;
}
