#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MN = 3005;
long long a[2], b[2], c[2], d[8], first[8], ra[2], rb[2], rc[2];
inline bool check(long long f3, long long f5, long long f6) {
  for (long long i = 0; i < 2; i++) ra[i] = a[i], rb[i] = b[i], rc[i] = c[i];
  ra[0] -= f5 + f6, rb[0] -= f3 + f6, rc[0] -= f3 + f5;
  if (ra[0] < 0 || rb[0] < 0 || rc[0] < 0) return 0;
  memset(first, 0, sizeof(first));
  first[3] = f3, first[5] = f5, first[6] = f6;
  first[7] = min({d[7], ra[0], rb[0], rc[0]});
  ra[0] -= first[7], rb[0] -= first[7], rc[0] -= first[7];
  first[4] = min(d[4], ra[0]);
  first[2] = min(d[2], rb[0]);
  first[1] = min(d[1], rc[0]);
  long long sa = 0, sb = 0, sc = 0;
  for (long long i = 1; i <= 7; i++) {
    long long second = d[i] - first[i];
    if (i & 1) sc += second;
    if (i & 2) sb += second;
    if (i & 4) sa += second;
  }
  if (sa > a[1] || sb > b[1] || sc > c[1]) return 0;
  for (long long i = 7; i >= 1; i--) printf("%lld ", first[i]);
  printf("\n");
  return 1;
}
int32_t main() {
  cin.tie(0), cin.sync_with_stdio(0);
  long long t;
  cin >> t;
outer:
  while (t--) {
    cin >> a[0] >> b[0] >> c[0] >> a[1] >> b[1] >> c[1];
    for (long long i = 1; i <= 7; i++) cin >> d[8 - i];
    long long tota = 0, totb = 0, totc = 0;
    for (long long i = 1; i <= 7; i++) {
      if (i & 1) totc += d[i];
      if (i & 2) totb += d[i];
      if (i & 4) tota += d[i];
    }
    if (tota > a[0] + a[1] || totb > b[0] + b[1] || totc > c[0] + c[1]) {
      printf("-1\n");
      continue;
    }
    for (long long i = 0; i <= d[3]; i++) {
      for (long long j = 0; j <= d[5]; j++) {
        for (long long k = 0; k <= d[6]; k++) {
          if (check(i, j, k)) goto outer;
        }
      }
    }
    printf("-1\n");
  }
  return 0;
}
