#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  a = a % 1000000007;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % 1000000007;
      b--;
    }
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
long long int gcd(long long int a, long long int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
using namespace std;
long long int solve(long long int x, long long int pos, long long int neg) {
  if (x > 0)
    return x * pos;
  else
    return (-x) * neg;
}
int main() {
  long long int T, mn, x, y;
  long long int c[7];
  cin >> T;
  while (T--) {
    cin >> x >> y;
    for (int i = 1; i <= 6; i++) cin >> c[i];
    mn = 2e18;
    mn = min(mn, solve(x, c[6], c[3]) + solve(y, c[2], c[5]));
    mn = min(mn, solve(x, c[1], c[4]) + solve(y - x, c[2], c[5]));
    mn = min(mn, solve(y, c[1], c[4]) + solve(x - y, c[6], c[3]));
    cout << mn << '\n';
  }
  return 0;
}
