#include <iostream>
#include <string>
using namespace std;

int toOnenum(int n)
{
    int sum = 0;
    if (n / 10 == 0)
    {
        return n;
    }
    else
    {
        while (n)
        {
            sum += n % 10;
            n /= 10;
        }
        return toOnenum(sum);
    }
}

void change(int num[6])
{
    for (int i = 0; i < 6; i++)
    {
        cout << toOnenum(num[i]) << ' ';
    }
    cout << endl;
}

int main()
{
    int n;
    cin >> n;
    string *arr;
    arr = new string[n];
    cin.get();
    for (int i = 0; i < n; i++)
    {
        getline(cin, arr[i]);
    }
    for (int i = 0; i < n; i++)
    {
        string buf = arr[i];
        int x = buf.length() / 6 + 1;
        string *str = new string[x];
        int z = 0;
        for (int j = 0; j < x; j++)
        {
            for (int k = 0; k < 6 && buf[z]; z++, k++)
            {
                str[j] += buf[z];
            }
        }
        for (int c = 0; c < x; c++, cout << endl)
        {
            cout << str[c];
        }
        int num[6] = {0, 0, 0, 0, 0, 0};
        for (int m = 0; m < x; m++)
        {
            for (int n = 0; n < str[m].length(); n++)
            {
                num[n] += str[m][n];
            }
        }
        change(num);
    }
    return 0;
}