#include <bits/stdc++.h>
using namespace std;
long long a[7];
long long T, X, Y, ans;
long long ABS(long long x) { return (x > 0) ? x : -x; }
int main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld", &X, &Y);
    for (int i = 1; i <= 6; i++) scanf("%lld", &a[i]);
    a[1] = min(a[1], a[6] + a[2]);
    a[6] = min(a[6], a[5] + a[1]);
    for (int i = 2; i <= 5; i++) {
      a[i] = min(a[i], a[i - 1] + a[i + 1]);
    }
    if (X <= Y && X >= 0) {
      X = ABS(X);
      Y = ABS(Y);
      ans = a[1] * X + a[2] * (Y - X);
    } else if (X < 0 && Y >= 0) {
      X = ABS(X);
      Y = ABS(Y);
      ans = a[2] * Y + a[3] * X;
    } else if (X < 0 && -X >= -Y && Y < 0) {
      X = ABS(X);
      Y = ABS(Y);
      ans = a[4] * Y + a[3] * (X - Y);
    } else if (X <= 0 && Y < 0 && -X < -Y) {
      X = ABS(X);
      Y = ABS(Y);
      ans = a[4] * X + a[5] * (Y - X);
    } else if (X > 0 && Y <= 0) {
      X = ABS(X);
      Y = ABS(Y);
      ans = a[6] * X + a[5] * Y;
    } else {
      X = ABS(X);
      Y = ABS(Y);
      ans = a[1] * Y + a[6] * (X - Y);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
