#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long int gcd(long long int a, long long int b) {
  if (a < b)
    return gcd(b, a);
  else if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long int isPrime(long long int n) {
  long long int p = (long long int)sqrt(n);
  for (int i = (2); i <= (p); i += (1))
    if (n % i == 0) return 0;
  return 1;
}
long long int pow(long long int b, long long int e) {
  if (e == 0)
    return 1;
  else if (e % 2 == 0) {
    long long int a = pow(b, e / 2);
    return a * a;
  } else {
    long long int a = pow(b, e / 2);
    return b * a * a;
  }
}
long long int powm(long long int x, long long int y,
                   long long int m = 1000000007) {
  x = x % m;
  long long int res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long int modInverse(long long int a, long long int m) {
  return powm(a, m - 2, m);
}
void solve() {
  long long int x, y;
  cin >> x >> y;
  long long int c[7];
  for (int i = (1); i <= (6); i += (1)) cin >> c[i];
  long long int ans = LLONG_MAX;
  int isnegx = 1, isnegy = 1;
  if (x < 0) isnegx = -1;
  if (y < 0) isnegy = -1;
  swap(x, y);
  if (x >= 0 and y >= 0) {
    if (x <= y) {
      ans = min({ans, c[1] * x + (y - x) * c[6], c[1] * y + (y - x) * c[5],
                 c[2] * x + c[6] * y});
    } else {
      ans = min({ans, c[1] * x + (x - y) * c[3], c[1] * y + (x - y) * c[2],
                 c[2] * x + c[6] * y});
    }
  } else if (x <= 0 and y <= 0) {
    x *= -1;
    y *= -1;
    if (x <= y) {
      ans = min({ans, c[4] * x + (y - x) * c[3], c[4] * y + (y - x) * c[2],
                 c[5] * x + c[3] * y});
    } else {
      ans = min({ans, c[4] * x + (x - y) * c[6], c[4] * y + (x - y) * c[5],
                 c[5] * x + c[3] * y});
    }
  } else {
    x = isnegx * abs(x);
    y = isnegy * abs(y);
    if (x <= 0) {
      x *= -1;
      ans = min({ans, c[1] * x + (x + y) * c[3], c[4] * y + (x + y) * c[2],
                 c[2] * x + c[3] * y});
    } else {
      y *= -1;
      ans = min({ans, c[4] * x + (x + y) * c[6], c[1] * y + (x + y) * c[5],
                 c[5] * x + c[6] * y});
    }
  }
  cout << ans << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
