#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &res) {
  char c;
  T flag = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  res = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
  res *= flag;
}
void wenjian() {
  freopen("concatenation.in", "r", stdin);
  freopen("concatenation.out", "w", stdout);
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long qpow(long long a, long long b, long long mod) {
  a %= mod;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ans;
}
struct chongzai {
  int c;
  bool operator<(const chongzai &b) const { return c > b.c; }
} sss;
const int maxn = 1e6 + 177;
const int maxm = 1e6 + 177;
const long long mod = 65536;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x, y;
    scanf("%d%d", &x, &y);
    long long c1, c2, c3, c4, c5, c6;
    scanf("%lld%lld%lld%lld%lld%lld", &c1, &c2, &c3, &c4, &c5, &c6);
    long long ys, yy, yx, zx, zz, zs;
    ys = min(c1, c2 + c6);
    yy = min(c2, c1 + c3);
    yx = min(c3, c2 + c4);
    zx = min(c4, c3 + c5);
    zz = min(c5, c4 + c6);
    zs = min(c6, c5 + c1);
    long long ans;
    if (x >= 0 && y >= 0) {
      ans = min(min(x, y) * ys + (y - min(x, y)) * yy + (x - min(x, y)) * zs,
                x * zs + (x + y) * yy);
    }
    if (x >= 0 && y < 0) {
      ans = min(x * zs + abs(y) * zz, (abs(y) + x) * zz + x * ys);
    }
    if (x < 0 && y >= 0) {
      ans = min(abs(x) * yx + y * yy, (abs(x) + y) * yy + zx * abs(x));
    }
    if (x < 0 && y < 0) {
      x = abs(x);
      y = abs(y);
      ans = min(min(x, y) * zx + (y - min(x, y)) * zz + (x - min(x, y)) * yx,
                (y + x) * zz + x * yx);
    }
    printf("%lld\n", ans);
  }
}
