#include <bits/stdc++.h>
using namespace std;

void executeTime() {
    cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
}

int main() {

    int n; cin >> n;

    vector<int> spf(n + 1, 1);

    spf[0] = 0;
    for (int i = 0; i <= n; i++) {
        spf[i] = i;
    }


    for (int i = 2; i <= sqrt(n); i++) {
        for (int j = i * i; j <= n; j += i) {
            if (spf[j] == j) spf[j] = i;
        }
    }

    vector<int> v(4);

    auto print_prime_factorisation = [&](int n) {
        map<int, int> mp;

        while (n > 1) {
            mp[spf[n]] ++;
            n /= spf[n];
        }

        for (auto &x : mp) {
            cout << x.first << ' ' << x.second << endl;
        }

        cout << endl;
    };

    for (auto &x : v) {
        cin >> x;
        print_prime_factorisation(x);
    }




    executeTime();
    return 0;
}