#include <bits/stdc++.h>
using namespace std;
int minFac[10000001];
int main() {
  ios::sync_with_stdio(0);
  for (int d = 2; d <= 3163; ++d) {
    if (minFac[d]) continue;
    int step = (d == 2 ? d : d + d);
    for (int j = d * d; j <= 10000000; j += step)
      if (!minFac[j]) minFac[j] = d;
  }
  int n;
  cin >> n;
  vector<pair<int, int>> res;
  for (int(i) = 0; (i) < (n); ++(i)) {
    int a;
    cin >> a;
    int fst = minFac[a] ? minFac[a] : a;
    int sec = 1;
    int ptr = a / fst;
    while (ptr != 1) {
      int mf = minFac[ptr];
      if (!mf) mf = ptr;
      if (mf != fst) sec *= mf;
      ptr /= mf;
    }
    if (sec != 1)
      res.emplace_back(fst, sec);
    else
      res.emplace_back(-1, -1);
  }
  for (int(i) = 0; (i) < (n); ++(i)) cout << res[i].first << " ";
  cout << endl;
  for (int(i) = 0; (i) < (n); ++(i)) cout << res[i].second << " ";
  cout << endl;
  return 0;
}
