#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
const long long mod = 1e9 + 7;
int isprime[N];
int n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 2; i < N; i++) {
    if (isprime[i]) continue;
    for (int j = i; j < N; j += i) isprime[j] = i;
  }
  cin >> n;
  vector<pair<int, int> > vp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int z = x;
    int y = 1;
    if (!isprime[x]) {
      vp.emplace_back(-1, -1);
      continue;
    }
    while (x % isprime[z] == 0) {
      x /= isprime[z];
      y *= isprime[z];
    }
    if (x > 1) {
      vp.emplace_back(x, y);
    } else
      vp.emplace_back(-1, -1);
  }
  for (int i = 0; i < n; i++) cout << vp[i].first << " ";
  cout << "\n";
  for (int i = 0; i < n; i++) cout << vp[i].second << " ";
}
