#include <bits/stdc++.h>
using namespace std;
long long int n, m;
long long int arr[300000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int TESTS, q, a, b, l, r, c, k, p, h, w, x, y, z, xs, ys, t, f;
  long double d;
  TESTS = 1;
  cin >> TESTS;
  while (TESTS--) {
    cin >> y >> x;
    for (long long int i = 0; i <= 5; i++) cin >> arr[i];
    long long int ans1, ans2, ans3;
    a = x - y;
    b = 0;
    if (a < 0)
      ans1 = abs(a) * arr[4];
    else
      ans1 = a * arr[1];
    if (y > 0)
      ans1 += y * arr[0];
    else
      ans1 += abs(y) * arr[3];
    if (x < 0)
      ans2 = abs(x) * arr[4];
    else
      ans2 = x * arr[1];
    if (y > 0)
      ans2 += y * arr[5];
    else
      ans2 += abs(y) * arr[2];
    b = y - x;
    if (b < 0)
      ans3 = abs(b) * arr[2];
    else
      ans3 = b * arr[5];
    if (x > 0)
      ans3 += x * arr[0];
    else
      ans3 += abs(x) * arr[3];
    cout << min(ans1, min(ans2, ans3)) << "\n";
  }
  return 0;
}
