#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int mod1 = 9999973;
const int mod2 = 1e9 + 7;
inline int rd() {
  int f = 1, x = 0;
  char s = getchar();
  while (!isdigit(s)) {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (isdigit(s)) {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
const int maxn = 1e5 + 10;
char s[maxn];
int c[7];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x, y;
    scanf("%d %d", &x, &y);
    for (int i = 1; i <= 6; ++i) scanf("%llu", &c[i]);
    for (int i = 0; i < 6; ++i) {
      c[1] = min(c[1], c[2] + c[6]);
      c[2] = min(c[2], c[1] + c[3]);
      c[3] = min(c[3], c[4] + c[2]);
      c[4] = min(c[4], c[3] + c[5]);
      c[5] = min(c[5], c[4] + c[6]);
      c[6] = min(c[6], c[1] + c[5]);
    }
    if (x == 0 || y == 0) {
      if (x == 0 && y == 0)
        printf("0\n");
      else if (x == 0) {
        unsigned long long ans = 0;
        if (y > 0)
          ans = (unsigned long long)y * (unsigned long long)c[2];
        else {
          y = -y;
          ans = (unsigned long long)y * (unsigned long long)c[5];
        }
        printf("%llu\n", ans);
      } else {
        unsigned long long ans = 0;
        if (x > 0)
          ans = (unsigned long long)x * (unsigned long long)c[6];
        else {
          x = -x;
          ans = (unsigned long long)x * (unsigned long long)c[3];
        }
        printf("%llu\n", ans);
      }
    } else if (x > 0 && y > 0) {
      unsigned long long ans = 0;
      if (x < y) {
        ans += (unsigned long long)x * (unsigned long long)c[1] +
               (unsigned long long)(y - x) * (unsigned long long)c[2];
      } else {
        ans += (unsigned long long)y * (unsigned long long)c[1] +
               (unsigned long long)(x - y) * (unsigned long long)c[6];
      }
      printf("%llu\n", ans);
    } else if (x < 0 && y < 0) {
      x = -x, y = -y;
      unsigned long long ans = 0;
      if (x < y) {
        ans += (unsigned long long)x * (unsigned long long)c[4] +
               (unsigned long long)(y - x) * (unsigned long long)c[5];
      } else {
        ans += (unsigned long long)y * (unsigned long long)c[4] +
               (unsigned long long)(x - y) * (unsigned long long)c[3];
      }
      printf("%llu\n", ans);
    } else if (x > 0 && y < 0) {
      unsigned long long ans = 0;
      y = -y;
      ans += (unsigned long long)x * (unsigned long long)c[6] +
             (unsigned long long)y * (unsigned long long)c[5];
      printf("%llu\n", ans);
    } else {
      unsigned long long ans = 0;
      x = -x;
      ans += (unsigned long long)x * (unsigned long long)c[3] +
             (unsigned long long)y * (unsigned long long)c[2];
      printf("%llu\n", ans);
    }
  }
  return 0;
}
