#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 3;
const long long nax = 2e6 + 2;
const long long max_val = 5e4 + 10;
const long long mod = 998244353;
const long long bits = 18;
long long caseNumber = 1;
void solve() {
  long long x, y;
  cin >> x >> y;
  vector<long long> c(6);
  for (int i = 0; i < 6; i++) cin >> c[i];
  bool isPosX = ((x >= 0) ? 1 : 0), isPosY = ((y >= 0) ? 1 : 0);
  if (isPosY == isPosX) {
    if (isPosY == 1) {
      long long z = min(x, y);
      long long fir = c[1] * y + c[5] * x;
      long long sec = z * c[0];
      long long ok = max(x, y);
      long long thi = ok * c[0];
      if (ok > x) {
        thi += c[2] * (ok - x);
      }
      if (ok > y) {
        thi += c[4] * (ok - y);
      }
      if (x > z) {
        sec += c[5] * (x - z);
      }
      if (y > z) {
        sec += c[1] * (y - z);
      }
      cout << min(min(fir, sec), thi) << "\n";
      return;
    } else {
      x = abs(x);
      y = abs(y);
      long long z = min(x, y);
      long long ok = max(x, y);
      long long fir = c[4] * y + c[2] * x;
      long long sec = z * c[3];
      long long thi = ok * (c[3]);
      if (x > z) {
        sec += c[2] * (x - z);
      }
      if (y > z) {
        sec += c[4] * (y - z);
      }
      if (ok > x) {
        thi += c[5] * (ok - x);
      }
      if (ok > y) {
        thi += c[1] * (ok - y);
      }
      cout << (min(fir, min(sec, thi))) << "\n";
      return;
    }
  } else {
    if (isPosX) {
      y = abs(y);
      long long fir = c[5] * x + c[4] * y;
      long long sec = c[3] * y + c[5] * (x + y);
      long long thi = c[0] * x + c[4] * (x + y);
      cout << min({fir, sec, thi}) << "\n";
      return;
    } else {
      x = abs(x);
      long long fir = c[2] * x + c[1] * y;
      long long sec = c[3] * x + c[1] * (x + y);
      long long thi = c[0] * y + c[2] * (x + y);
      cout << min({fir, sec, thi}) << "\n";
      return;
    }
  }
}
bool TestCase1 = 1;
bool isGoogles = 0;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  t = 1;
  if (TestCase1) {
    cin >> t;
  }
  long long here = 1;
  while (t--) {
    solve();
  }
  return 0;
}
