#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long long int x, y;
  long long int c1, c2, c3, c4, c5, c6;
  cin >> t;
  while (t--) {
    cin >> x >> y;
    cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
    long long int ans = (abs(x) * (c6 * (x > 0) + c3 * (x < 0)) +
                         abs(y) * (c2 * (y > 0) + c5 * (y < 0)));
    {
      ans = min(ans, abs(y - x) * (c6 * (x - y > 0) + c3 * (x - y < 0)) +
                         abs(y) * (c1 * (y > 0) + c4 * (y < 0)));
      ans = min(ans, abs(y - x) * (c2 * (x - y < 0) + c5 * (x - y > 0)) +
                         abs(x) * (c1 * (x > 0) + c4 * (x < 0)));
    }
    cout << ans << "\n";
  }
}
