#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
    long long n;
    if (!(cin >> n)) return;

    string s = to_string(n);
    int len = s.length();

    for (int l = max(1, len - 1); l <= len; ++l) {
        int half = (l + 1) / 2;
        long long base = 1;
        for (int i = 0; i < half - 1; ++i) base *= 10;
        
        long long start = base;
        long long end = base * 10 - 1;

        if (l == len) {
            end = stoll(s.substr(0, half));
        }

        for (long long first_half = end; first_half >= start && first_half >= end - 2000; --first_half) {
            string s_half = to_string(first_half);
            string a_str = s_half;
            for (int i = l / 2 - 1; i >= 0; --i) {
                a_str += s_half[i];
            }
            
            long long a = stoll(a_str);
            if (a <= n && (n - a) % 12 == 0) {
                cout << a << " " << n - a << "\n";
                return;
            }
        }
    }
    cout << -1 << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    if (cin >> t) {
        while (t--) {
            solve();
        }
    }
    return 0;
}