#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll cost[7];
ll cost1(ll x, ll y) {
  ll res = 0LL;
  if (x < 0) {
    res += -x * cost[3];
  } else {
    res += x * cost[6];
  }
  if (y < 0) {
    res += -y * cost[5];
  } else {
    res += y * cost[2];
  }
  return res;
}
ll cost2(ll x, ll y) {
  ll res = 0LL;
  if (x > 0) {
    res += x * cost[1];
    y -= x;
  } else {
    res += -x * cost[4];
    y -= x;
  }
  if (y < 0) {
    res += -y * cost[5];
  } else {
    res += y * cost[2];
  }
  return res;
}
ll cost3(ll x, ll y) {
  ll res = 0LL;
  if (y > 0) {
    res += y * cost[1];
    x -= y;
  } else {
    res += -y * cost[4];
    x -= y;
  }
  if (x < 0) {
    res += -x * cost[3];
  } else {
    res += x * cost[6];
  }
  return res;
}
void solve() {
  ll x, y;
  cin >> x >> y;
  for (int i = 1; i <= 6; ++i) cin >> cost[i];
  ll ans1 = cost1(x, y);
  ll ans2 = cost2(x, y);
  ll ans3 = cost3(x, y);
  ll ans = min({ans1, ans2, ans3});
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
