#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    long long ans = 0;
    long long a, b, c, d, e, f;
    scanf("%lld%lld%lld%lld%lld%lld", &a, &b, &c, &d, &e, &f);
    a = min(a, f + b), b = min(b, a + c), c = min(c, b + d);
    d = min(d, c + e), e = min(e, d + f), f = min(f, e + a);
    if (x * y > 0) {
      if (x < 0) {
        x = abs(x), y = abs(y);
        long long mi = min(x, y);
        if (d < c + e) x -= mi, y -= mi, ans += mi * d;
        ans += x * c + y * e;
      } else {
        long long mi = min(x, y);
        if (a < b + f) x -= mi, y -= mi, ans += mi * a;
        ans += x * f + y * b;
      }
    } else {
      if (x > 0)
        ans += x * f;
      else
        ans += abs(x) * c;
      if (y > 0)
        ans += y * b;
      else
        ans += abs(y) * e;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
