#include <bits/stdc++.h>
using namespace std;
int rd() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * f;
}
int T, a[3], b[3], c[3];
int ans[8], flag;
vector<int> d;
bool check1(int A_1, int B_1, int C_1, int A_2, int B_2, int C_2,
            vector<int> cnt) {
  ans[5] = min(min(B_1, C_1), cnt[5]);
  cnt[5] -= ans[5];
  B_1 -= ans[5];
  C_1 -= ans[5];
  ans[4] = min(cnt[4], A_1);
  cnt[4] -= ans[4];
  A_1 -= ans[4];
  ans[6] = min(cnt[6], B_1);
  cnt[6] -= ans[6];
  B_1 -= ans[6];
  ans[7] = min(C_1, cnt[7]);
  C_1 -= ans[7];
  cnt[7] -= ans[7];
  if (cnt[1] + cnt[2] + cnt[3] + cnt[4] > A_2) return false;
  if (cnt[1] + cnt[2] + cnt[5] + cnt[6] > B_2) return false;
  if (cnt[1] + cnt[3] + cnt[5] + cnt[7] > C_2) return false;
  return true;
}
void check(int A_1, int B_1, int C_1, int A_2, int B_2, int C_2,
           vector<int> Cnt, int num) {
  if (flag) return;
  int x = min(Cnt[1], min(A_1, min(B_1, C_1)));
  ans[1] = x;
  Cnt[1] -= x;
  A_1 -= x;
  B_1 -= x;
  C_1 -= x;
  for (int i = 0; i <= Cnt[2]; i++)
    for (int j = 0; j <= Cnt[3]; j++) {
      if (i + j > A_1 || i > B_1 || j > C_1) break;
      ans[2] = i;
      ans[3] = j;
      Cnt[2] -= i;
      Cnt[3] -= j;
      A_1 -= i + j;
      B_1 -= i;
      C_1 -= j;
      if (check1(A_1, B_1, C_1, A_2, B_2, C_2, Cnt)) {
        flag = num;
        return;
      }
      Cnt[2] += i;
      Cnt[3] += j;
      A_1 += i + j;
      B_1 += i;
      C_1 += j;
    }
}
int main() {
  T = rd();
  d.resize(8);
  for (int e = 1; e <= T; e++) {
    flag = 0;
    a[1] = rd();
    b[1] = rd();
    c[1] = rd();
    a[2] = rd();
    b[2] = rd();
    c[2] = rd();
    for (int i = 1; i <= 7; i++) d[i] = rd();
    check(a[1], b[1], c[1], a[2], b[2], c[2], d, 1);
    check(a[2], b[2], c[2], a[1], b[1], c[1], d, 2);
    if (!flag)
      puts("-1");
    else {
      for (int i = 1; i <= 7; i++)
        printf("%d ", (flag == 1) ? ans[i] : d[i] - ans[i]);
      puts("");
    }
  }
  return 0;
}
