#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long t;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y;
    long long arr[6];
    for (long long i = 0; i < 6; i++) {
      cin >> arr[i];
    }
    if (x == 0 && y == 0) {
      cout << 0 << endl;
      continue;
    }
    long long a[6];
    memset(a, 0, sizeof(a));
    if (x > 0) {
      a[5] = x;
    }
    if (x < 0) {
      a[2] = (-1) * x;
    }
    if (y > 0) {
      a[1] = y;
    }
    if (y < 0) {
      a[4] = (-1) * y;
    }
    long long sum = 0;
    for (long long i = 0; i < 6; i++) {
      long long ex = a[(i + 1) % 6];
      long long ey;
      if (i == 0) {
        ey = a[5];
      } else {
        ey = a[i - 1];
      }
      long long mn = min(ex, ey);
      a[i] += mn;
      a[(i + 1) % 6] -= mn;
      if (i == 0) {
        a[5] -= mn;
      } else {
        a[i - 1] -= mn;
      }
    }
    for (long long i = 0; i < 6; i++) {
      long long ex = arr[(i - 1) % 6] * a[i];
      long long ey = arr[(i + 1) % 6] * a[i];
      if (i == 0) {
        ex = arr[5] * a[i];
      }
      sum += min(arr[i] * a[i], ex + ey);
    }
    cout << sum << endl;
  }
  return 0;
}
