#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long M = 5e4 + 10;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f3f3f3f3f;
int main() {
  long long t, x, y, c[10];
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld%lld", &x, &y);
    for (long long i = 1; i <= 6; ++i) scanf("%lld", &c[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[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]);
    long long minn = inf;
    if (x > 0 && y > 0) {
      long long tmp = min(x, y) * c[1];
      if (x > y)
        tmp += c[6] * (x - y);
      else
        tmp += c[2] * (y - x);
      minn = min(minn, tmp);
    } else if (x > 0 && y <= 0) {
      long long tmp = c[6] * x - c[5] * y;
      minn = min(minn, tmp);
    } else if (x <= 0 && y > 0) {
      long long tmp = c[2] * y - c[3] * x;
      minn = min(minn, tmp);
    } else {
      x = -x, y = -y;
      long long tmp = min(x, y) * c[4];
      if (x > y)
        tmp += (x - y) * c[3];
      else
        tmp += (y - x) * c[5];
      minn = min(minn, tmp);
    }
    printf("%lld\n", minn);
  }
  return 0;
}
