#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll maxSize = 5007;
ll c[7];
ll calc25(ll x) { return (x > 0) ? x * c[2] : -x * c[5]; }
ll calc36(ll x) { return (x > 0) ? x * c[6] : -x * c[3]; }
ll calc14(ll x) { return (x > 0) ? x * c[1] : -x * c[4]; }
ll calcSum12(ll x, ll y) { return calc14(x) + calc25(y - x); }
ll calcSum13(ll x, ll y) { return calc14(y) + calc36(x - y); }
ll calcSum23(ll x, ll y) { return calc25(y) + calc36(x); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll q;
  cin >> q;
  while (q > 0) {
    ll x, y;
    cin >> x >> y;
    for (ll i = 1; i <= 6; ++i) cin >> c[i];
    ll answer = min(calcSum12(x, y), calcSum13(x, y));
    answer = min(answer, calcSum23(x, y));
    cout << answer;
    --q;
    if (q > 0) cout << "\n";
  }
}
