#include <bits/stdc++.h>
using namespace std;
double const eps = 1e-7;
struct LP {
  int n;
  vector<vector<double> > e;
  void adeq(vector<double> const &v) { e.push_back(v); }
  int bad() {
    for (int i = 1; i < (int)(e.size()); ++i)
      if (e[i][n] < -eps) {
        for (int j = 0; j < (int)(n); ++j)
          if (e[i][j] < -eps) return j;
        return -2;
      }
    return -1;
  }
  int getkl() {
    for (int i = 0; i < (int)(n); ++i)
      if (e[0][i] > eps) return i;
    return -1;
  }
  int getmn(int j) {
    int an = 0;
    double mn = 1e18;
    for (int i = 1; i < (int)(e.size()); ++i)
      if (e[i][j] > eps) {
        double t = e[i][n] / e[i][j];
        if (t < mn) mn = t, an = i;
      }
    return an;
  }
  void kl(int j) {
    int i = getmn(j);
    double t = e[i][j];
    for (int k = 0; k < (int)(e[i].size()); ++k) e[i][k] /= t;
    for (int k = 0; k < (int)(e.size()); ++k)
      if (k != i) {
        double z = e[k][j];
        for (int w = 0; w < (int)(e[k].size()); ++w) e[k][w] -= z * e[i][w];
      }
  }
  void pl() {
    int t = e[0].size() - 1;
    n = e[0].size() + e.size() - 2;
    for (int i = 0; i < (int)(e.size()); ++i) e[i].resize(n + 1);
    for (int i = 1; i < (int)(e.size()); ++i) swap(e[i][t], e[i][n]);
    for (int i = 1; i < (int)(e.size()); ++i) e[i][t + i - 1] = 1.0;
  }
  pair<double, bool> solve() {
    pl();
    int j;
    while ((j = bad()) >= 0) kl(j);
    if (j == -2) return make_pair(0.0, false);
    while ((j = getkl()) >= 0) kl(j);
    return make_pair(-e[0][n], true);
  }
  vector<double> gtval(int m) {
    vector<char> vis(e.size());
    vis[0] = true;
    vector<double> an(m);
    for (int i = 0; i < (int)(m); ++i)
      if (abs(e[0][i]) < eps) {
        int j = 0;
        for (int k = 1; k < (int)(e.size()); ++k)
          if (abs(e[k][i]) > eps) {
            if (j) {
              j = 0;
              break;
            }
            j = k;
          }
        if (!vis[j]) {
          an[i] = e[j][n] / e[j][i];
          vis[j] = true;
        }
      }
    return an;
  }
};
int g[2][3], fr[8];
bool ok(vector<int> const &v) {
  int sm[2][3] = {};
  for (int i = 0; i < (int)(v.size()); ++i)
    for (int j = 0; j < (int)(3); ++j)
      if (i + 1 >> j & 1) {
        sm[0][j] += v[i];
        sm[1][j] += fr[i + 1] - v[i];
      }
  for (int i = 0; i < (int)(3); ++i)
    if (g[0][2 - i] < sm[0][i] || g[1][2 - i] < sm[1][i]) return false;
  return true;
}
void solve() {
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(3); ++j) scanf("%d", g[i] + j);
  for (int i = 7; i > 0; --i) scanf("%d", fr + i);
  LP s;
  vector<double> v(8);
  s.adeq(v);
  for (int i = 0; i < (int)(7); ++i) {
    for (int j = 0; j < (int)(7); ++j) v[j] = 0;
    v[i] = 1;
    v[7] = fr[i + 1];
    s.adeq(v);
    v[i] = -1;
    v[7] = 0;
    s.adeq(v);
  }
  for (int i = 0; i < (int)(3); ++i) {
    for (int j = 1; j < (int)(8); ++j) v[j - 1] = j >> i & 1;
    v[7] = g[0][2 - i];
    s.adeq(v);
    int z = 0;
    for (int j = 1; j < (int)(8); ++j)
      if (v[j - 1]) {
        v[j - 1] *= -1;
        z += fr[j];
      }
    v[7] = -(z - g[1][2 - i]);
    s.adeq(v);
  }
  if (!s.solve().second) {
    printf("-1\n");
    return;
  }
  vector<double> val = s.gtval(7);
  vector<int> an(7);
  for (int i = 0; i < (int)(1 << 7); ++i) {
    for (int j = 0; j < (int)(7); ++j)
      an[j] = val[j] + 0.5 + (i >> j & 1 ? -eps : eps);
    if (ok(an)) break;
  }
  if (!ok(an)) {
    printf("-1\n");
    return;
  }
  for (int i = 0; i < (int)(7); ++i) printf("%d ", an[6 - i]);
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
