#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct node {
  long long dis, x, y;
  node() {}
  node(long long ndis, long long nx, long long ny) : dis(ndis), x(nx), y(ny) {}
  friend bool operator<(const node &A, const node &B) { return A.dis > B.dis; }
};
priority_queue<node> Q;
const int dx[6] = {1, 0, -1, -1, 0, 1}, dy[6] = {1, 1, 0, -1, -1, 0};
long long dis[5][5];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    memset(dis, 0x3f3f3f3f3f, sizeof(dis));
    dis[0][0] = 0;
    long long x, y;
    cin >> x >> y;
    cin >> dis[2][2] >> dis[1][2] >> dis[0][1] >> dis[0][0] >> dis[1][0] >>
        dis[2][1];
    Q.emplace(dis[2][2], 2, 2);
    Q.emplace(dis[1][2], 1, 2);
    Q.emplace(dis[0][1], 0, 1);
    Q.emplace(dis[0][0], 0, 0);
    Q.emplace(dis[1][0], 1, 0);
    Q.emplace(dis[2][1], 2, 1);
    while (Q.size()) {
      node np = Q.top();
      Q.pop();
      long long ndis = np.dis, nx = np.x, ny = np.y;
      if (ndis != dis[nx][ny]) continue;
      for (int i = 0; i < 6; i++) {
        long long nex = nx + dx[i], ney = ny + dy[i];
        if (nex > 2 || ney > 2 || nex < 0 || ney < 0) continue;
        if (dis[nex][ney] > ndis + dis[dx[i] + 1][dy[i] + 1]) {
          dis[nex][ney] = ndis + dis[dx[i] + 1][dy[i] + 1];
          Q.emplace(dis[nex][ney], nex, ney);
        }
      }
    }
    long long rex, rey, mkx = (x < 0), mky = (y < 0);
    x = abs(x);
    y = abs(y);
    if (x > y) {
      rex = x - y;
      rey = 0;
      x = y;
    } else
      rex = 0, rey = y - x, y = x;
    long long res = 0;
    res = (rex ? (dis[1 + (mkx ? -1 : 1)][1] * rex)
               : (dis[1][1 + (mky ? -1 : 1)] * rey));
    if (x) res += x * dis[1 + (mkx ? -1 : 1)][1 + (mky ? -1 : 1)];
    cout << res << '\n';
  }
}
