#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 1e6 + 10;
void solve() {
  int a[2][3];
  int v[8];
  int an[8];
  for (int k = 0; k < (2); ++k)
    for (int i = 0; i < (3); ++i) R(a[k][2 - i]);
  for (int i = (1); i <= (7); ++i) {
    R(v[8 - i]);
  }
  int ll[3], rr[3];
  int sum[3] = {};
  for (int i = (1); i <= (7); ++i) {
    for (int j = 0; j < (3); ++j) {
      if ((i >> j) & 1) sum[j] += v[i];
    }
  }
  for (int i = 0; i < (3); ++i) {
    if (sum[i] > a[0][i] + a[1][i]) {
      W(-1);
      return;
    }
  }
  for (int i = 0; i < (3); ++i) rr[i] = a[0][i];
  ll[0] = max(0, v[3] + v[5] + v[7] - a[1][0]);
  ll[1] = max(0, v[3] + v[6] + v[7] - a[1][1]);
  ll[2] = max(0, v[5] + v[6] + v[7] - a[1][2]);
  for (int i = (max({ll[0], ll[1], ll[2]})); i <= (v[3] + v[5] + v[6] + v[7]);
       ++i) {
    int s[3], b[3];
    bool err = 0;
    for (int j = 0; j < (3); ++j) {
      s[j] = max(0, i - rr[j]);
      b[j] = min(v[7 ^ (1 << j)], i - ll[j]);
      if (s[j] > b[j]) err = 1;
    }
    if (err) continue;
    if (i - b[0] - b[1] - b[2] > v[7]) continue;
    for (int j = 0; j < (3); ++j) {
      int tmp = max(0, min(b[0] + b[1] + b[2] - i, b[j] - s[j]));
      b[j] -= tmp;
    }
    if (i - b[0] - b[1] - b[2] < 0) continue;
    an[6] = b[0];
    an[5] = b[1];
    an[3] = b[2];
    an[7] = i - b[0] - b[1] - b[2];
    an[1] = min(v[1], rr[0] - an[3] - an[5] - an[7]);
    an[2] = min(v[2], rr[1] - an[3] - an[6] - an[7]);
    an[4] = min(v[4], rr[2] - an[5] - an[6] - an[7]);
    for (int j = 7; j > 0; j--) printf("%d%c", an[j], " \n"[j == 1]);
    return;
  }
  W(-1);
}
int main() {
  int ___T;
  scanf("%d", &___T);
  for (int cs = 1; cs <= ___T; cs++) {
    solve();
  }
  return 0;
}
