#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
long long T, x, y, c[10];
int main() {
  cin >> T;
  while (T--) {
    cin >> x >> y;
    for (long long i = 1; i <= 6; i++) cin >> c[i];
    if (x < 0 && y < 0) {
      long long tot = min(abs(x), abs(y));
      long long tot2 = max(abs(x), abs(y));
      long long res1 = 0, res2 = 0, res3 = 0;
      res1 = abs(x) * c[3] + abs(y) * c[5];
      x += tot;
      y += tot;
      res2 = tot * c[4] + abs(x) * c[3] + abs(y) * c[5];
      x -= tot;
      y -= tot;
      x += tot2;
      y += tot2;
      res3 = tot2 * c[4] + abs(x) * c[6] + abs(y) * c[2];
      cout << min(res1, min(res2, res3)) << endl;
    } else if (x >= 0 && y < 0) {
      long long tot = min(abs(x), abs(y));
      long long res1 = 0, res2 = 0, res3 = 0;
      res1 = c[6] * x + c[5] * abs(y);
      res2 = c[1] * x + (abs(y) + x) * c[5];
      res3 = c[4] * abs(y) + (abs(y) + x) * c[6];
      cout << min(res1, min(res2, res3)) << endl;
    } else if (x < 0 && y >= 0) {
      long long tot = min(abs(x), abs(y));
      long long res1 = 0, res2 = 0, res3 = 0;
      res1 = c[3] * abs(x) + c[2] * y;
      res2 = c[4] * abs(x) + (abs(x) + y) * c[2];
      res3 = c[1] * y + (abs(x) + y) * c[3];
      cout << min(res1, min(res2, res3)) << endl;
    } else if (x >= 0 && y >= 0) {
      long long tot = min(abs(x), abs(y));
      long long tot2 = max(abs(x), abs(y));
      long long res1 = 0, res2 = 0, res3 = 0;
      res1 = x * c[6] + y * c[2];
      x -= tot;
      y -= tot;
      res2 = tot * c[1] + x * c[6] + y * c[2];
      x += tot;
      y += tot;
      x -= tot2;
      y -= tot2;
      res3 = tot2 * c[1] + abs(x) * c[3] + abs(y) * c[5];
      cout << min(res1, min(res2, res3)) << endl;
    }
  }
  return 0;
}
