#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long x, y, c1, c2, c3, c4, c5, c6;
  cin >> x >> y;
  cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
  swap(x, y);
  if (x >= 0 && y >= 0) {
    long long res = x * c2 + y * c6;
    long long temp = min(x, y);
    res = min(res, res - temp * (c2 + c6) + temp * c1);
    res =
        min(res, max(x, y) * c1 + (max(x, y) - y) * c3 + (max(x, y) - x) * c5);
    cout << res << "\n";
    return;
  }
  if (x <= 0 && y >= 0) {
    x = -x;
    long long res = x * c5 + y * c6;
    res = min(res, res - y * c6 + y * (c1 + c5));
    res = min(res, res - x * c5 + x * (c4 + c6));
    cout << res << "\n";
    return;
  }
  if (x <= 0 && y <= 0) {
    x = -x;
    y = -y;
    long long res = x * c5 + y * c3;
    long long temp = min(x, y);
    res = min(res, res - temp * (c3 + c5) + temp * c4);
    res =
        min(res, max(x, y) * c4 + (max(x, y) - y) * c6 + (max(x, y) - x) * c2);
    cout << res << "\n";
    return;
  }
  if (x >= 0 && y <= 0) {
    y = -y;
    long long res = x * c2 + y * c3;
    res = min(res, res - y * c3 + y * (c4 + c2));
    res = min(res, res - x * c2 + x * (c1 + c3));
    cout << res << "\n";
    return;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
