#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int TC;
int freq[2][3];
int num[8], ans[8];
int32_t main() {
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> TC;
  while (TC--) {
    for (auto i = (0); i < (2); i++) {
      for (auto j = (0); j < (3); j++) {
        cin >> freq[i][j];
      }
    }
    cin >> num[7] >> num[3] >> num[5] >> num[1] >> num[6] >> num[2] >> num[4];
    bool found = false;
    for (auto i = (0); i < (num[3] + 1); i++) {
      for (auto j = (0); j < (num[5] + 1); j++) {
        if (freq[0][0] - i - j < 0) break;
        for (auto k = (0); k < (num[6] + 1); k++) {
          if (freq[0][1] - i - k < 0 || freq[0][2] - j - k < 0) break;
          int lt[3] = {freq[0][0] - i - j, freq[0][1] - i - k,
                       freq[0][2] - j - k};
          int rt[3] = {freq[1][0] - (num[3] - i) - (num[5] - j),
                       freq[1][1] - (num[3] - i) - (num[6] - k),
                       freq[1][2] - (num[5] - j) - (num[6] - k)};
          if (rt[0] < 0 || rt[1] < 0 || rt[2] < 0) continue;
          ans[7] = min(min(lt[0], num[7]), min(lt[1], lt[2]));
          if (ans[7] + min(rt[0], min(rt[1], rt[2])) < num[7]) continue;
          lt[0] -= ans[7];
          lt[1] -= ans[7];
          lt[2] -= ans[7];
          int sb = (num[7] - ans[7]);
          rt[0] -= sb;
          rt[1] -= sb;
          rt[2] -= sb;
          if (lt[0] + rt[0] < num[1] || lt[1] + rt[1] < num[2] ||
              lt[2] + rt[2] < num[4])
            continue;
          ans[3] = i;
          ans[5] = j;
          ans[6] = k;
          ans[1] = min(num[1], lt[0]);
          ans[2] = min(num[2], lt[1]);
          ans[4] = min(num[4], lt[2]);
          found = true;
          break;
        }
        if (found) break;
      }
      if (found) break;
    }
    if (!found) {
      cout << "-1\n";
      continue;
    }
    cout << ans[7] << ' ' << ans[3] << ' ' << ans[5] << ' ' << ans[1] << ' '
         << ans[6] << ' ' << ans[2] << ' ' << ans[4] << '\n';
  }
}
