#include <bits/stdc++.h>
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("O3,no-stack-protector")
using namespace std;
int64_t GetCoeff(int i, int diff, const vector<int64_t>& c) {
  if (i == 0) {
    return (diff > 0 ? c[6] : c[3]);
  } else if (i == 1) {
    return (diff > 0 ? c[2] : c[5]);
  } else if (i == 2) {
    return (diff > 0 ? c[1] : c[4]);
  }
  throw runtime_error("invalid i in GetCoeff");
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int tc;
  cin >> tc;
  while (tc--) {
    int64_t x0, y0;
    cin >> x0 >> y0;
    vector<int64_t> c(7);
    for (int i = 1; i <= 6; ++i) {
      cin >> c[i];
    }
    vector<int64_t> pts = {0, x0, y0};
    int64_t best = numeric_limits<int64_t>::max();
    for (int64_t z : pts) {
      vector<int64_t> pt = {x0 - z, y0 - z, z};
      int64_t cur = 0;
      for (int i = 0; i < 3; ++i) {
        cur += GetCoeff(i, pt[i], c) * abs(pt[i]);
      }
      best = min(best, cur);
    }
    cout << best << '\n';
  }
  return 0;
}
