#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long int x, y, c1, c2, c3, c4, c5, c6;
    vector<long long int> ans(3);
    cin >> x >> y;
    cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
    if (y > 0)
      ans[0] += c2 * y, ans[1] += c1 * y;
    else
      ans[0] += c5 * abs(y), ans[1] += c4 * abs(y);
    if (x > 0)
      ans[0] += c6 * x, ans[2] += c1 * x;
    else
      ans[0] += c3 * abs(x), ans[2] += c4 * abs(x);
    if (x > y)
      ans[1] += c6 * (x - y), ans[2] += c5 * (x - y);
    else
      ans[1] += c3 * (y - x), ans[2] += c2 * (y - x);
    sort(ans.begin(), ans.end());
    cout << ans[0] << endl;
  }
}
