#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 12, M = 1e7 + 1;
int n, a[N], b[N];
int p[M];
bitset<M> ch;
int main() {
  for (int i = 2; i < M; i++) {
    if (ch[i]) continue;
    for (long long j = i; j < M; j += i) {
      p[j] = i;
      ch[j] = 1;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    int now;
    cin >> now;
    int first = p[now];
    while (now % first == 0) now /= first;
    if (now == 1)
      a[i] = b[i] = -1;
    else {
      a[i] = first;
      b[i] = now;
    }
  }
  for (int i = 0; i < n; i++) cout << a[i] << ' ';
  cout << '\n';
  for (int i = 0; i < n; i++) cout << b[i] << ' ';
  return 0;
}
