#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t-- > 0) {
    long long int x;
    long long int y;
    cin >> x;
    cin >> y;
    long long int c[6];
    for (int i = 0; i < 6; i++) cin >> c[i];
    int flag = 1;
    while (flag == 1) {
      flag = 0;
      if (c[0] + c[4] < c[5]) {
        c[5] = c[0] + c[4];
        flag = 1;
      }
      if (c[5] + c[1] < c[0]) {
        c[0] = c[5] + c[1];
        flag = 1;
      }
      if (c[0] + c[2] < c[1]) {
        c[1] = c[0] + c[2];
        flag = 1;
      }
      if (c[1] + c[3] < c[2]) {
        c[2] = c[1] + c[3];
        flag = 1;
      }
      if (c[2] + c[4] < c[3]) {
        c[3] = c[2] + c[4];
        flag = 1;
      }
      if (c[3] + c[5] < c[4]) {
        c[4] = c[3] + c[5];
        flag = 1;
      }
    }
    long long int cost = 0;
    if ((x == 0) && (y == 0))
      cout << 0 << endl;
    else {
      if (x >= 0 && y >= 0) {
        cost = cost + c[0] * min(x, y);
        if (y > x) {
          cost = cost + c[1] * (y - x);
        } else
          cost = cost + c[5] * (x - y);
      } else if (x <= 0 && y <= 0) {
        cost = cost - c[3] * max(x, y);
        if (y > x) {
          cost = cost + c[2] * (y - x);
        } else
          cost = cost + c[4] * (x - y);
      } else {
        if (x < 0) {
          cost = cost - x * c[2];
        } else if (x > 0) {
          cost = cost + x * c[5];
        }
        if (y < 0) {
          cost = cost - y * c[4];
        } else if (y > 0) {
          cost = cost + y * c[1];
        }
      }
      cout << cost << endl;
    }
  }
  return 0;
}
