#include <bits/stdc++.h>
using namespace std;
pair<int, int> merge(pair<int, int> a, pair<int, int> b) {
  return {max(a.first, b.first), min(a.second, b.second)};
}
int a1, b1, c1, a2, b2, c2, d1, d2, d3, d4, d5, d6, d7, s1, s2, s3, ans1, ans2,
    ans3, ans4, ans5, ans6, ans7;
pair<int, int> range_a, range_b, range_c;
void print() {
  cout << ans1 << ' ' << ans2 << ' ' << ans3 << ' ' << ans4 << ' ' << ans5
       << ' ' << ans6 << ' ' << ans7 << '\n';
}
bool chk(int x) {
  if (!d1 && x & 1) return false;
  int A, B, C;
  if (x <= d1)
    A = d2, B = d3, C = d5, ans1 = x, ans2 = ans3 = ans5 = 0;
  else {
    if (x - d1 & 1)
      A = d2 - (x - d1 + 1) / 2, B = d3 - (x - d1 + 1) / 2,
      C = d5 - (x - d1 + 1) / 2, ans1 = d1 - 1,
      ans2 = ans3 = ans5 = (x - d1 + 1) / 2;
    else
      A = d2 - (x - d1) / 2, B = d3 - (x - d1) / 2, C = d5 - (x - d1) / 2,
      ans1 = d1, ans2 = ans3 = ans5 = (x - d1) / 2;
  }
  if (A < 0 || B < 0 || C < 0) return false;
  pair<int, int> Range_a = {max(range_a.first - x - d4, 0), range_a.second - x};
  pair<int, int> Range_b = {max(range_b.first - x - d6, 0), range_b.second - x};
  pair<int, int> Range_c = {max(range_c.first - x - d7, 0), range_c.second - x};
  if (Range_a.second < 0 || Range_b.second < 0 || Range_c.second < 0)
    return false;
  pair<int, int> r1 = merge({0, B}, Range_a), r2 = merge({0, C}, Range_b),
                 r3 = merge({r1.first + r2.first, r1.second + r2.second},
                            Range_c);
  if (r1.first <= r1.second && r2.first <= r2.second && r3.first <= r3.second) {
    int cnt1 = r1.first, cnt2 = r2.first, cnt3 = r1.first + r2.first;
    if (r1.second - r1.first >= r3.first - cnt3)
      cnt1 += r3.first - cnt3, cnt3 = r3.first;
    else {
      cnt1 = r1.second;
      cnt3 += r1.second - r1.first;
      cnt2 += r3.first - cnt3;
      cnt3 = r3.first;
    }
    ans3 += cnt1;
    ans5 += cnt2;
    cnt1 += x;
    cnt2 += x;
    cnt3 += x;
    ans4 = max(0, range_a.first - cnt1);
    ans6 = max(0, range_b.first - cnt2);
    ans7 = max(0, range_c.first - cnt3);
    print();
    return true;
  }
  r1 = merge({0, A}, Range_a), r2 = merge({0, C}, Range_c),
  r3 = merge({r1.first + r2.first, r1.second + r2.second}, Range_b);
  if (r1.first <= r1.second && r2.first <= r2.second && r3.first <= r3.second) {
    int cnt1 = r1.first, cnt2 = r1.first + r2.first, cnt3 = r2.first;
    if (r1.second - r1.first >= r3.first - cnt2)
      cnt1 += r3.first - cnt2, cnt2 = r3.first;
    else {
      cnt1 = r1.second;
      cnt2 += r1.second - r1.first;
      cnt3 += r3.first - cnt2;
      cnt2 = r3.first;
    }
    ans2 += cnt1;
    ans5 += cnt3;
    cnt1 += x;
    cnt2 += x;
    cnt3 += x;
    ans4 = max(0, range_a.first - cnt1);
    ans6 = max(0, range_b.first - cnt2);
    ans7 = max(0, range_c.first - cnt3);
    print();
    return true;
  }
  r1 = merge({0, A}, Range_b), r2 = merge({0, B}, Range_c),
  r3 = merge({r1.first + r2.first, r1.second + r2.second}, Range_a);
  if (r1.first <= r1.second && r2.first <= r2.second && r3.first <= r3.second) {
    int cnt1 = r1.first + r2.first, cnt2 = r1.first, cnt3 = r2.first;
    if (r1.second - r1.first >= r3.first - cnt1)
      cnt2 += r3.first - cnt1, cnt1 = r3.first;
    else {
      cnt2 = r1.second;
      cnt1 += r1.second - r1.first;
      cnt3 += r3.first - cnt1;
      cnt1 = r3.first;
    }
    ans2 += cnt2;
    ans3 += cnt3;
    cnt1 += x;
    cnt2 += x;
    cnt3 += x;
    ans4 = max(0, range_a.first - cnt1);
    ans6 = max(0, range_b.first - cnt2);
    ans7 = max(0, range_c.first - cnt3);
    print();
    return true;
  }
  return false;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> a1 >> b1 >> c1 >> a2 >> b2 >> c2;
    cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6 >> d7;
    s1 = d1 + d2 + d3 + d4;
    s2 = d1 + d2 + d5 + d6;
    s3 = d1 + d3 + d5 + d7;
    range_a = {s1 - a2, a1};
    range_b = {s2 - b2, b1};
    range_c = {s3 - c2, c1};
    if (range_a.first > range_a.second || range_b.first > range_b.second ||
        range_c.first > range_c.second) {
      cout << -1 << '\n';
      continue;
    }
    bool flg = false;
    for (int i = 0; i <= 3000; i++)
      if (chk(i)) {
        flg = true;
        break;
      }
    if (!flg) cout << -1 << '\n';
  }
  return 0;
}
