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