#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const int oo = INT_MAX;
const long long OO = LLONG_MAX;
long long c1, c2, c3, c4, c5, c6;
long long res1, res2, res3, res4;
int t;
long long x, y;
void solve() {
  res1 = res2 = res3 = 0;
  if (x < 0) {
    res1 = c4 * (-x);
  }
  if (x > 0) {
    res1 = c1 * x;
  }
  if (x < y) {
    res1 += c2 * (y - x);
  }
  if (x > y) {
    res1 += c5 * (x - y);
  }
  if (y > 0) {
    res2 = c1 * y;
  }
  if (y < 0) {
    res2 = c4 * -y;
  }
  if (x < y) {
    res2 += c3 * (y - x);
  }
  if (x > y) {
    res2 += c6 * (x - y);
  }
  if (x > 0) {
    res3 = c6 * x;
  }
  if (x < 0) {
    res3 = c3 * -x;
  }
  if (0 < y) {
    res3 += c2 * y;
  }
  if (0 > y) {
    res3 += c5 * -y;
  }
  cout << min(res1, min(res2, res3)) << '\n';
}
void input() {
  cin >> x >> y;
  cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    input();
    solve();
  }
}
