#include <bits/stdc++.h>
using namespace std;
const int NMX = (int)5e5 + 5;
const int AMX = (int)1e7 + 5;
int a[NMX], pf[AMX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 2; i < AMX; i++) {
    if (pf[i]) continue;
    for (int j = 2 * i; j < AMX; j += i) {
      if (pf[j] != 0) continue;
      pf[j] = i;
    }
  }
  vector<array<int, 2>> ans(n, {-1, -1});
  for (int i = 0; i < n; i++) {
    if (pf[a[i]] == 0) continue;
    int d = a[i];
    while (d && d % pf[a[i]] == 0) {
      d /= pf[a[i]];
    }
    if (d != 1) ans[i] = {pf[a[i]], d};
  }
  for (auto &i : ans) cout << i[0] << ' ';
  cout << '\n';
  for (auto &i : ans) cout << i[1] << ' ';
  return 0;
}
