#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 228;
const int INF = (int)1e9 + 228;
long long c[6], mn[6];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tst;
  cin >> tst;
  while (tst--) {
    long long x, y;
    cin >> x >> y;
    for (int i = 0; i < 6; i++) {
      cin >> c[i];
    }
    for (int i = 0; i < 6; i++) {
      mn[i] = min(c[i], c[(i - 1 + 6) % 6] + c[(i + 1) % 6]);
    }
    long long ans = 0;
    if (x >= 0 && y >= 0) {
      if (y >= x) {
        ans = mn[0] * x + mn[1] * (y - x);
      } else {
        ans = mn[0] * y + mn[5] * (x - y);
      }
    } else if (x >= 0 && y <= 0) {
      ans = mn[5] * x + mn[4] * (-y);
    } else if (x <= 0 && y <= 0) {
      if (-y >= -x) {
        ans = mn[3] * (-x) + mn[4] * (x - y);
      } else {
        ans = mn[3] * (-y) + mn[2] * (y - x);
      }
    } else {
      ans = mn[2] * (-x) + mn[1] * y;
    }
    cout << ans << "\n";
  }
  return 0;
}
