#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
long long c[10];
signed main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    long long x, y;
    cin >> x >> y >> c[1] >> c[2] >> c[3] >> c[4] >> c[5] >> c[6];
    for (long long i = 2; i <= 5; i++) {
      c[i] = min(c[i], c[i + 1] + c[i - 1]);
    }
    c[1] = min(c[1], c[2] + c[6]);
    c[6] = min(c[6], c[1] + c[5]);
    for (long long i = 2; i <= 5; i++) {
      c[i] = min(c[i], c[i + 1] + c[i - 1]);
    }
    c[1] = min(c[1], c[2] + c[6]);
    c[6] = min(c[6], c[1] + c[5]);
    long long ans = 0;
    if (x >= 0 && y >= 0) {
      x = abs(x);
      y = abs(y);
      long long k = min(x, y);
      ans = min(x, y) * c[1];
      x -= k;
      y -= k;
      ans += x * c[6] + y * c[2];
    } else if (x <= 0 && y >= 0) {
      x = abs(x);
      y = abs(y);
      ans += x * c[3] + y * c[2];
    } else if (x <= 0 && y <= 0) {
      x = abs(x);
      y = abs(y);
      long long k = min(x, y);
      ans = min(x, y) * c[4];
      x -= k;
      y -= k;
      ans += x * c[3] + y * c[5];
    } else {
      x = abs(x);
      y = abs(y);
      ans += x * c[6] + y * c[5];
    }
    cout << ans << endl;
  }
}
