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