#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;
ll inf = 4e18, mod = 1e9 + 7;
ll c1, c2, c3, c4, c5, c6;
ll funcx(ll sx, ll ex) {
  if (sx == ex) return 0;
  if (sx < ex) return (ex - sx) * min(c6, c1 + c5);
  if (sx > ex) return (sx - ex) * min(c3, c2 + c4);
}
ll funcy(ll sy, ll ey) {
  if (sy == ey) return 0;
  if (sy < ey) return (ey - sy) * min(c2, c1 + c3);
  if (sy > ey) return (sy - ey) * min(c5, c4 + c6);
}
ll funcxy(ll sx, ll sy, ll ex, ll ey) {
  if (sx - ex != sy - ey) return inf;
  if (sx < ex && sy < ey)
    return min((ex - sx) * c1, funcx(sx, ex) + funcy(sy, ey));
  if (sx > ex && sy > ey)
    return min((sx - ex) * c4, funcx(sx, ex) + funcy(sy, ey));
}
void(o_o)() {
  ll x, y;
  cin >> x >> y;
  cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;
  ll res = funcx(0, x) + funcy(0, y);
  res = min(res, funcxy(0, 0, x, x) + funcy(x, y));
  res = min(res, funcxy(0, 0, y, y) + funcx(y, x));
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  int t = 1;
  cin >> t;
  while (t--) (o_o)();
}
