#include <bits/stdc++.h>
using namespace std;
int g[2][3], fr[8], z[2][3], f5[2], f3[2], an[8];
bool ok(int a, int b) {
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(3); ++j) z[i][j] = g[i][j];
  for (int i = 0; i < (int)(3); ++i) z[0][i] -= a;
  for (int i = 0; i < (int)(3); ++i) z[1][i] -= fr[7] - a;
  for (int i = 0; i < (int)(2); ++i) z[0][i] -= b;
  for (int i = 0; i < (int)(2); ++i) z[1][i] -= fr[6] - b;
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(3); ++j)
      if (z[i][j] < 0) return false;
  for (int i = 0; i < (int)(2); ++i) f5[i] = f3[i] = 0;
  for (int i = 0; i < (int)(2); ++i) {
    if (z[i][2] > z[i][1]) {
      int t = min(fr[5] - f5[0] - f5[1], min(z[i][2] - z[i][1], z[i][0]));
      f5[i] += t;
      z[i][2] -= t;
      z[i][0] -= t;
    }
    if (z[i][2] > z[i][0]) {
      int t = min(fr[3] - f3[0] - f3[1], min(z[i][2] - z[i][0], z[i][1]));
      f3[i] += t;
      z[i][2] -= t;
      z[i][1] -= t;
    }
  }
  for (int i = 0; i < (int)(2); ++i) {
    int t = min(fr[5] - f5[0] - f5[1], min(z[i][0], z[i][2]));
    f5[i] += t;
    z[i][0] -= t;
    z[i][2] -= t;
    t = min(fr[3] - f3[0] - f3[1], min(z[i][1], z[i][2]));
    f3[i] += t;
    z[i][1] -= t;
    z[i][2] -= t;
  }
  if (fr[3] > f3[0] + f3[1] || fr[5] > f5[0] + f5[1] ||
      fr[1] > z[0][2] + z[1][2] || fr[2] > z[0][1] + z[1][1] ||
      fr[4] > z[0][0] + z[1][0])
    return false;
  an[1] = min(fr[1], z[0][2]);
  an[2] = min(fr[2], z[0][1]);
  an[3] = f3[0];
  an[4] = min(fr[4], z[0][0]);
  an[5] = f5[0];
  an[6] = b;
  an[7] = a;
  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);
  for (int i = 0; i < (int)(fr[7] + 1); ++i)
    for (int j = 0; j < (int)(fr[6] + 1); ++j)
      if (ok(i, j)) {
        for (int i = 1; i < (int)(8); ++i) printf("%d ", an[8 - i]);
        printf("\n");
        return;
      }
  printf("-1\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
