#include <bits/stdc++.h>
using namespace std;
void solve() {
  int x, y;
  cin >> x >> y;
  array<int64_t, 7> cost;
  for (int i = 1; i <= 6; ++i) {
    cin >> cost[i];
  }
  auto path_cost = [&](int64_t x, int64_t plus, int64_t minus) -> int64_t {
    return (x >= 0 ? plus : -minus) * x;
  };
  int64_t best = numeric_limits<int64_t>::max();
  best = min(best,
             path_cost(x, cost[6], cost[3]) + path_cost(y, cost[2], cost[5]));
  best = min(best, path_cost(y, cost[1], cost[4]) +
                       path_cost(x - y, cost[6], cost[3]));
  best = min(best, path_cost(x, cost[1], cost[4]) +
                       path_cost(y - x, cost[2], cost[5]));
  cout << best << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.precision(10);
  std::cout << std::fixed << std::boolalpha;
  int t = 1;
  std::cin >> t;
  while (t--) solve();
  return 0;
}
