#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 998244353;
constexpr long long mod = 1e9 + 7;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const long long N = 3e5 + 5;
vector<long long> adj[N];
long long power(long long n, long long p) {
  if (p == 0) return 1;
  if (p == 1) return n;
  if (p % 2)
    return power(n, p - 1) * n;
  else {
    long long x = power(n, p / 2);
    return x * x;
  }
}
long long modpow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
long long nsum(long long num) { return (num * (num + 1)) / 2; }
void edge(long long u, long long v) {
  adj[u].push_back(v);
  adj[v].push_back(u);
}
void solve() {
  long long x, y, c1, c2, c3, c4, c5, c6;
  string s;
  cin >> x >> y;
  cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
  c1 = min(c1, c6 + c2);
  c2 = min(c2, c1 + c3);
  c3 = min(c3, c2 + c4);
  c4 = min(c4, c3 + c5);
  c5 = min(c5, c4 + c6);
  c6 = min(c6, c5 + c1);
  long long ans = 0;
  if (x >= 0 && y >= 0) {
    long long mn = min(x, y);
    x -= mn;
    y -= mn;
    ans += mn * c1;
  }
  if (x < 0 && y < 0) {
    long long mn = max(x, y);
    x -= mn;
    y -= mn;
    ans += abs(mn) * c4;
  }
  if (x >= 0) {
    ans += x * c6;
  }
  if (x < 0) {
    ans += abs(x) * c3;
  }
  if (y >= 0) {
    ans += y * c2;
  }
  if (y < 0) ans += abs(y) * c5;
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long Test = 1;
  cin >> Test;
  while (Test--) {
    solve();
  }
  return 0;
}
