#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
set<int> S;
vector<vector<int> > vs;
vector<int> sums;
vector<int> tmp;
void dfs(int x, int sum) {
  if (x == 6) {
    if (S.count(sum) == 0) {
      S.insert(sum);
      vs.push_back(tmp);
      sums.push_back(sum);
    }
    return;
  }
  tmp.push_back(0);
  dfs(x + 1, sum);
  tmp.back() = 4;
  dfs(x + 1, sum + 4);
  tmp.back() = 7;
  dfs(x + 1, sum + 7);
  tmp.pop_back();
}
void init() { dfs(0, 0); }
bool dp[20][10];
struct P {
  int digit, k;
  int use;
  P(int digit, int k, int use) : digit(digit), k(k), use(use) {}
  P() {}
};
P pre[21][10];
int main() {
  init();
  cout << vs.size() << endl;
  int T;
  cin >> T;
  while (T--) {
    long long n;
    cin >> n;
    for (int i = 0; i < (int)21; ++i)
      for (int j = 0; j < (int)10; ++j) {
        dp[i][j] = 0;
        pre[i][j].digit = -1;
      }
    dp[0][0] = 1;
    for (int i = 0; i < (int)20; ++i) {
      int a = n % 10;
      n /= 10;
      for (int j = 0; j < (int)10; ++j) {
        if (!dp[i][j]) continue;
        for (int k = 0; k < (int)vs.size(); ++k) {
          int s = j + sums[k];
          if (s % 10 == a) {
            dp[i + 1][s / 10] = 1;
            pre[i + 1][s / 10] = P(i, j, k);
          }
        }
      }
    }
    if (dp[20][0]) {
      P cur = P(20, 0, 0);
      vector<int> ans(6);
      while (1) {
        cur = pre[cur.digit][cur.k];
        if (cur.digit == -1) break;
        for (int i = 0; i < (int)6; ++i) {
          ans[i] = ans[i] * 10 + vs[cur.use][i];
        }
      }
      for (int i = 0; i < (int)6; ++i) cout << ans[i] << " ";
      cout << endl;
    } else {
      puts("-1");
    }
  }
}
