#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int ksm(int a, int b) {
  int ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1) ans = ans * a % mod;
  return ans;
}
template <typename T>
inline void read(T &x) {
  x = 0;
  int fu = 1;
  char c = getchar();
  while (c > 57 || c < 48) {
    if (c == 45) fu = -1;
    c = getchar();
  }
  while (c <= 57 && c >= 48) {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  x *= fu;
}
template <typename T, typename... Args>
inline void read(T &x, Args &...arg) {
  read(x);
  read(arg...);
}
template <typename T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
long long a[7];
long long ex, ey;
long long make() {
  long long x, y;
  long long ans = 2e19;
  if (ex > 0) {
    x = ex, y = 0;
    if (ey > 0)
      ans = min(ans, x * a[5] + abs(ey) * a[1]);
    else
      ans = min(ans, x * a[5] + (abs(ey) * a[4]));
    x = ex, y = ex;
    if (ey > ex)
      ans = min(ans, x * a[0] + abs(ey - y) * a[1]);
    else
      ans = min(ans, x * a[0] + abs(y - ey) * a[4]);
  } else {
    x = ex, y = 0;
    if (ey > 0)
      ans = min(ans, -x * a[2] + abs(ey) * a[1]);
    else
      ans = min(ans, -x * a[2] + (abs(-ey) * a[4]));
    x = ex, y = ex;
    if (ey > ex)
      ans = min(ans, -x * a[3] + abs(ey - y) * a[1]);
    else
      ans = min(ans, -x * a[3] + abs(y - ey) * a[4]);
  }
  if (ex > 0 & 0 < ey && ey < ex) {
    ans = min(ans, ey * a[0] + abs(ex - ey) * a[5]);
  } else if (ex < 0 && ex < ey && ey < 0) {
    ans = min(ans, -ey * a[3] + abs(ex - ey) * a[2]);
  }
  return ans;
}
void work() {
  cin >> ex >> ey;
  for (long long i = 0; i <= 5; i++) {
    cin >> a[i];
  }
  for (long long k = 1; k <= 10; k++) {
    long long p, l, pp, ll;
    for (long long i = 0; i <= 5; i++) {
      p = (i - 1 + 6) % 6;
      l = (i + 1 + 6) % 6;
      pp = (i - 2 + 6) % 6;
      ll = (i + 2 + 6) % 6;
      a[i] = min(a[i], a[l] + a[p]);
    }
  }
  long long ans = 0;
  ans = make();
  cout << ans << endl;
}
signed main() {
  long long t;
  cin >> t;
  while (t--) work();
  return 0;
}
