#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int SIEVEN = 10000001;
int lp[SIEVEN + 1];
int ps[SIEVEN];
int nps;
void sieve() {
  memset(lp, 0, sizeof(lp));
  nps = 0;
  for (int i = 2; i <= SIEVEN; i++) {
    if (not lp[i]) lp[i] = ps[nps++] = i;
    for (int j = 0; j < nps and ps[j] <= lp[i] and i * ps[j] <= SIEVEN; j++)
      lp[i * ps[j]] = ps[j];
  }
}
int main() {
  ios::sync_with_stdio(false);
  sieve();
  int n;
  cin >> n;
  vector<pair<int, int>> ans(n);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int p = lp[a];
    int d = 1;
    while (a % p == 0) {
      a /= p;
      d *= p;
    }
    if (a == 1) {
      ans[i].first = ans[i].second = -1;
    } else {
      ans[i].first = d;
      ans[i].second = a;
    }
  }
  for (auto e : ans) cout << e.first << ' ';
  cout << endl;
  for (auto e : ans) cout << e.second << ' ';
  cout << endl;
}
