#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> all(n);
  for (int i = 0; i < n; i++) cin >> all[i];
  vector<bool> p(10000);
  vector<int> f;
  for (int i = 2; i < 10000; i++) {
    if (p[i]) continue;
    f.push_back(i);
    int k = 2 * i;
    while (k < 10000) {
      p[k] = 1;
      k += i;
    }
  }
  vector<pair<int, int>> g(n);
  for (int i = 0; i < n; i++) {
    int x = -1;
    g[i] = {-1, -1};
    for (auto c : f) {
      if (all[i] % c == 0) {
        x = 1;
        while (all[i] % c == 0) {
          x *= c;
          all[i] /= c;
        }
        break;
      }
    }
    if (x > 1 && all[i] > 1) {
      g[i] = {x, all[i]};
    }
  }
  for (int i = 0; i < n; i++) cout << g[i].first << ' ';
  cout << endl;
  for (int i = 0; i < n; i++) cout << g[i].second << ' ';
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  t = 1;
  while (t > 0) {
    t--;
    solve();
  }
}
