#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 2e2 + 10;
long long c[8];
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    for (int i = 1; i <= 6; i++) {
      scanf("%lld", &c[i]);
    }
    for (int i = 1; i <= 6; i++) {
      c[2] = min(c[2], c[1] + c[3]);
      c[6] = min(c[6], c[1] + c[5]);
      c[3] = min(c[3], c[2] + c[4]);
      c[1] = min(c[1], c[2] + c[6]);
      c[4] = min(c[4], c[3] + c[5]);
      c[5] = min(c[5], c[4] + c[6]);
    }
    long long ans;
    if (x >= 0 && y >= 0) {
      if (x > y) {
        ans = y * c[1] + (x - y) * c[6];
      } else {
        ans = x * c[1] + (y - x) * c[2];
      }
    } else if (x >= 0 && y < 0) {
      ans = -y * c[5] + c[6] * x;
    } else if (x < 0 && y >= 0) {
      ans = -x * c[3] + y * c[2];
    } else {
      if (x >= y)
        ans = c[4] * -x + (x - y) * c[5];
      else
        ans = c[4] * -y + c[3] * (y - x);
    }
    cout << ans << endl;
  }
  return 0;
}
