#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const double PI = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long c[7];
long long rec(long long x, long long y) {
  if (x == 0 && y == 0) return 0;
  if (x == 0) {
    if (y > 0) {
      long long ans = min(c[2] * y, y * (c[3] + c[1]));
      return ans;
    } else {
      long long aby = abs(y);
      long long ans = min(aby * c[5], aby * (c[4] + c[6]));
      return ans;
    }
  } else if (y == 0) {
    if (x > 0) {
      long long ans = min(c[6] * x, x * (c[5] + c[1]));
      return ans;
    } else {
      long long ans = min(c[3] * (-x), (-x) * (c[2] + c[4]));
      return ans;
    }
  }
  long long ans = 4e18;
  if (x > 0) {
    long long tmp = min(c[6] * x, x * (c[5] + c[1])) + rec(0, y);
    ans = min(ans, tmp);
  } else {
    long long tmp = min(c[3] * (-x), (-x) * (c[2] + c[4])) + rec(0, y);
    ans = min(ans, tmp);
  }
  if (y > 0) {
    long long tmp = min(c[2] * y, y * (c[3] + c[1])) + rec(x, 0);
    ans = min(ans, tmp);
  } else {
    long long aby = abs(y);
    long long tmp = min(aby * c[5], aby * (c[4] + c[6])) + rec(x, 0);
    ans = min(ans, tmp);
  }
  if (x > 0) {
    long long tmp = c[1] * x + rec(0, y - x);
    ans = min(ans, tmp);
  } else {
    long long tmp = c[4] * (-x) + rec(0, y - x);
    ans = min(ans, tmp);
  }
  if (y > 0) {
    long long tmp = c[1] * y + rec(x - y, 0);
    ans = min(ans, tmp);
  } else {
    long long tmp = c[4] * (-y) + rec(x - y, 0);
    ans = min(ans, tmp);
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    for (long long i = 1; i <= 6; i++) {
      cin >> c[i];
    }
    cout << rec(x, y) << "\n";
  }
}
