#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int n = 3;
int a[2][n], c[2][n];
int b[1 << n], first[1 << n];
void answer() {
  for (int i = 0; i < 2; i++)
    for (int j = n - 1; ~j; j--) {
      cin >> a[i][j];
    }
  for (int i = (1 << n) - 1; i; i--) cin >> b[i];
  for (first[3] = 0; first[3] <= b[3]; first[3]++)
    for (first[5] = 0; first[5] <= b[5]; first[5]++)
      for (first[6] = 0; first[6] <= b[6]; first[6]++) {
        first[7] = b[7];
        memcpy(c, a, sizeof(c));
        for (int i = 0; i < n; i++) {
          if ((3 >> i) & 1) c[0][i] -= first[3], c[1][i] += first[3] - b[3];
          if ((5 >> i) & 1) c[0][i] -= first[5], c[1][i] += first[5] - b[5];
          if ((6 >> i) & 1) c[0][i] -= first[6], c[1][i] += first[6] - b[6];
          first[7] = min(first[7], c[0][i]);
        }
        bool t = 1;
        for (int i = 0; i < n; i++) {
          c[0][i] -= first[7], c[1][i] += first[7] - b[7];
          first[1 << i] = min(b[1 << i], c[0][i]);
          c[0][i] -= first[1 << i], c[1][i] += first[1 << i] - b[1 << i];
          t &= c[0][i] >= 0 && c[1][i] >= 0;
        }
        if (t) {
          cout << first[7];
          for (int i = (1 << n) - 2; i; i--) cout << " " << first[i];
          cout << '\n';
          return;
        }
      }
  cout << -1 << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) answer();
  return 0;
}
