#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void one();
int main() {
  fastio();
  int t = 1;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    one();
  }
  return 0;
}
long long c[6];
long long d[6];
void one() {
  int x, y;
  cin >> x >> y;
  for (int i = 0; i < 6; ++i) cin >> c[i];
  for (int i = 0; i < 6; ++i) {
    d[i] = min(c[i], c[(i - 1 + 6) % 6] + c[(i + 1 + 6) % 6]);
  }
  map<pair<int, int>, long long> ma;
  ma[{1, 1}] = d[0];
  ma[{0, 1}] = d[1];
  ma[{-1, 0}] = d[2];
  ma[{-1, -1}] = d[3];
  ma[{0, -1}] = d[4];
  ma[{1, 0}] = d[5];
  long long ans = 0;
  if (y >= 0 && x >= 0) {
    if (y >= x) {
      ans = (y - x) * ma[{0, 1}] + x * ma[{1, 1}];
    } else {
      ans = min(y, x) * ma[{1, 1}] + (max(x, y) - min(x, y)) * ma[{1, 0}];
    }
  } else if (y >= 0 && x <= 0) {
    ans = (y)*ma[{0, 1}] + (-x) * ma[{-1, 0}];
  } else if (x >= 0 && y <= 0) {
    ans = (-y) * ma[{0, -1}] + (x)*ma[{1, 0}];
  } else {
    if (y >= x) {
      ans = min(-y, -x) * ma[{-1, -1}] +
            (max(-x, -y) - min(-x, -y)) * ma[{-1, 0}];
    } else {
      ans = (-y - -x) * ma[{0, -1}] + (-x) * ma[{-1, -1}];
    }
  }
  cout << ans << "\n";
}
