#include <bits/stdc++.h>
using namespace std;
long long T, x, y, c1, c2, c3, c4, c5, c6, ans, tp;
inline void cal() {
  if (y > 0)
    ans += min(c1 + c5, c6) * y;
  else if (y < 0)
    ans -= min(c3, c4 + c2) * y;
  if (x > 0)
    ans += min(c2, c3 + c1) * x;
  else if (x < 0)
    ans -= min(c5, c4 + c6) * x;
}
int main() {
  cin >> T;
  while (T--) {
    cin >> y >> x;
    ans = 0;
    cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
    if (x * y > 0) {
      if (x > 0) {
        tp = min(x, y);
        ans += min(c2 + c6, c1) * tp;
        x -= tp;
        y -= tp;
      }
      if (x < 0) {
        tp = min(-x, -y);
        ans += min(c4, c3 + c5) * tp;
        x += tp;
        y += tp;
      }
    }
    cal();
    cout << ans << endl;
  }
  return 0;
}
