#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<long long int> c(7);
void update() {
  c[1] = min(c[1], c[2] + c[6]);
  c[2] = min(c[2], c[3] + c[1]);
  c[3] = min(c[3], c[2] + c[4]);
  c[4] = min(c[4], c[3] + c[5]);
  c[5] = min(c[5], c[4] + c[6]);
  c[6] = min(c[6], c[5] + c[1]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int tt = 1;
  cin >> tt;
  while (tt--) {
    int x, y;
    cin >> y >> x;
    for (int i = 1; i <= 6; i++) cin >> c[i];
    update();
    long long int ans = 0;
    if (y > 0) {
      long long int ans1, ans2;
      ans1 = y * c[6] + abs(x) * (x > 0 ? c[2] : c[5]);
      if (x > 0 && c[6] + c[2] > c[1]) {
        ans1 = ans1 - min(y, x) * (c[6] + c[2]) + min(y, x) * c[1];
      }
      ans2 = y * c[1] + abs(y - x) * (x > y ? c[2] : c[5]);
      if (x < y && c[1] + c[5] > c[6]) {
        ans2 = ans2 - min(y, abs(y - x)) * (c[1] + c[5]) +
               min(y, abs(y - x)) * c[6];
      }
      ans = min(ans1, ans2);
    } else if (y == 0) {
      if (x > 0) {
        ans = x * (c[1] + c[3]);
        ans = min(ans, x * c[2]);
      } else if (x < 0) {
        ans = abs(x) * (c[6] + c[4]);
        ans = min(ans, abs(x) * c[5]);
      }
    } else if (y < 0) {
      long long int ans1, ans2;
      ans1 = abs(y) * c[4] + abs(y - x) * (x > y ? c[2] : c[5]);
      if (x > y && c[4] + c[2] > c[3]) {
        ans1 = ans1 - min(abs(y), abs(y - x)) * (c[2] + c[4]) +
               min(abs(y), abs(y - x)) * c[3];
      }
      ans2 = abs(y) * c[3] + abs(x) * (x > 0 ? c[2] : c[5]);
      if (x < 0 && c[3] + c[5] > c[4]) {
        ans2 = ans2 - min(abs(y), abs(x)) * (c[5] + c[3]) +
               min(abs(y), abs(x)) * c[4];
      }
      ans = min(ans1, ans2);
    }
    cout << ans << "\n";
  }
  return 0;
}
