#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;
}
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
int t, n;
long long x, y;
long long c[15];
void init() {
  c[1] = min(c[1], c[6] + c[2]);
  c[2] = min(c[2], c[1] + c[3]);
  c[3] = min(c[3], c[2] + c[4]);
  c[4] = min(c[4], c[3] + c[5]);
  c[5] = min(c[5], c[4] + c[6]);
  c[6] = min(c[6], c[5] + c[1]);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld", &x, &y);
    for (int i = 1; i <= 6; i++) {
      scanf("%lld", &c[i]);
    }
    init();
    long long res = 1e19;
    if (x >= 0 && y <= 0) {
      y = abs(y);
      res = min(res, c[6] * x + y * c[5]);
    } else if (x <= 0 && y >= 0) {
      x = abs(x);
      res = min(res, c[3] * x + y * c[2]);
    } else if (x >= 0 && y >= 0) {
      res = min(res, min(x, y) * c[1] + (y - min(x, y)) * c[2] +
                         (x - min(x, y)) * c[6]);
    } else {
      x = abs(x);
      y = abs(y);
      res = min(res, min(x, y) * c[4] + (y - min(x, y)) * c[5] +
                         (x - min(x, y)) * c[3]);
    }
    printf("%lld\n", res);
  }
  return 0;
}
