#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long x, y;
  cin >> x >> y;
  long long c[6];
  for (long long& cost : c) cin >> cost;
  long long cost1 = 0, cost2 = 0, cost3 = 0;
  cost1 = x * (x > 0 ? c[5] : -c[2]) + y * (y > 0 ? c[1] : -c[4]);
  cost2 = x * (x > 0 ? c[0] : -c[3]) + (x - y) * (x - y > 0 ? c[4] : -c[1]);
  cost3 = (y - x) * (y - x > 0 ? c[2] : -c[5]) + y * (y > 0 ? c[0] : -c[3]);
  cout << min({cost1, cost2, cost3});
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << '\n';
  }
  return 0;
}
