#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    long long X, Y;
    cin >> X >> Y;
    long long A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    long long ans = 4e18;
    if (Y >= X && X >= 0) {
      ckmin(ans, A * X + B * (Y - X));
    }
    if (Y >= 0 && X <= Y) {
      ckmin(ans, Y * A + (Y - X) * C);
    }
    if (X >= 0 && Y <= X) {
      ckmin(ans, X * A + (X - Y) * E);
    }
    if (X >= Y && Y >= 0) {
      ckmin(ans, A * Y + F * (X - Y));
    }
    if (Y <= X && X <= 0) {
      ckmin(ans, D * (-X) + E * (X - Y));
    }
    if (X <= Y && Y <= 0) {
      ckmin(ans, D * (-Y) + C * (Y - X));
    }
    if (Y <= 0 && Y <= X) {
      ckmin(ans, D * (-Y) + F * (X - Y));
    }
    if (X <= 0 && X <= Y) {
      ckmin(ans, D * (-X) + B * (Y - X));
    }
    long long xc = X * F;
    if (X < 0) xc = (-X) * C;
    long long yc = Y * B;
    if (Y < 0) yc = (-Y) * E;
    cout << min(ans, xc + yc) << nl;
  }
  return 0;
}
