#include <bits/stdc++.h>
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
  std::cout << a << ' ';
  err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
  for (auto &v : arg) std::cout << v << ' ';
  err(args...);
}
using namespace std;
const long long mod = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 1e5 + 5;
long long C[3][2];
void solve() {
  long long x, y;
  cin >> x >> y;
  cin >> C[0][0] >> C[2][0] >> C[1][1] >> C[0][1] >> C[2][1] >> C[1][0];
  long long ans = 3e18;
  int d1 = 0, d2 = 0;
  if (x < 0) d1 = 1;
  if (x > y) d2 = 1;
  ans = min(ans, C[0][d1] * abs(x) + abs(x - y) * C[2][d2]);
  d1 = 0, d2 = 0;
  if (y < 0) d1 = 1;
  if (y > x) d2 = 1;
  ans = min(ans, C[0][d1] * abs(y) + abs(x - y) * C[1][d2]);
  d1 = 0, d2 = 0;
  if (x < 0) d1 = 1;
  if (y < 0) d2 = 1;
  ans = min(ans, C[1][d1] * abs(x) + abs(y) * C[2][d2]);
  cout << ans << endl;
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
