#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <algorithm>
#include <random>
#include <chrono>
#include <iostream>
#include <functional>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#define PII pair<int, int>
#define vec vector
#define str string
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const int N = 1e7 + 10;
const int inf = 0x3f3f3f3f;
const ll INF = 1e18;
const double eps = 1e-8;
int T;
int lpf[N], pr[N], cnt;
PII ans[(int) 5e5 + 10];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
for (int i = 2; i < N; i++) {
if (!lpf[i]) pr[++cnt] = i, lpf[i] = i;
for (int j = 1; j <= cnt && 1LL * i * pr[j] < (ll) N; j++) {
lpf[pr[j] * i] = pr[j];
if (i % pr[j] == 0) break;
}
}
int n; cin >> n;
for (int i = 1; i <= n; i++) {
int x, t, tt = 1; cin >> x, t = x;
while (t != 1) {
int d = lpf[t]; tt *= d;
while (t % d == 0) t /= d;
}
if (tt != lpf[x]) {
ans[i] = {lpf[x], tt / lpf[x]};
} else ans[i] = {-1, -1};
}
for (int i = 1; i <= n; i++) cout << ans[i].fi << ' ';
cout << '\n';
for (int i = 1; i <= n; i++) cout << ans[i].se << ' ';
cout << '\n';
return 0;
}