#include <bits/stdc++.h>
using namespace std;
int up, down, mleft, mright;
int c[10];
long long myabs(long long a) {
  if (a < 0) return -a;
  return a;
}
void solve() {
  long long x, y;
  cin >> x >> y >> c[1];
  swap(x, y);
  cin >> mright >> down >> c[4] >> mleft >> up;
  c[1] = min(c[1], mright + up);
  c[4] = min(c[4], mleft + down);
  for (int i = (1), iend = (20); i <= iend; i++)
    mright = min(mright, c[1] + down), up = min(up, c[1] + mleft),
    mleft = min(mleft, c[4] + up), down = min(down, c[4] + mright);
  long long ans = 0;
  if (x < 0 && y < 0) {
    int used = min(myabs(x), myabs(y));
    ans = 1ll * used * c[4] + 1ll * (myabs(x) - used) * mleft +
          1ll * (myabs(y) - used) * down;
  } else if (x > 0 && y > 0) {
    int used = min(myabs(x), myabs(y));
    ans = 1ll * used * c[1] + 1ll * (myabs(x) - used) * mright +
          1ll * (myabs(y) - used) * up;
  } else {
    if (x > 0)
      ans += 1ll * myabs(x) * mright;
    else
      ans += 1ll * myabs(x) * mleft;
    if (y > 0)
      ans += 1ll * myabs(y) * up;
    else
      ans += 1ll * myabs(y) * down;
  }
  cout << ans << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
}
