#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 1;
const int inf = 0x3f3f3f3f;
const int M = 1e7 + 1;
const double Pi = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
template <class T, class F>
inline void mem(T a, F b, int c) {
  for (int i = 0; i <= c; ++i) a[i] = b;
}
template <class T>
inline void read(T &x, T xk = 10) {
  char ch = getchar();
  T f = 1, t = 0.1;
  for (x = 0; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch <= '9' && ch >= '0'; ch = getchar()) x = x * xk + ch - '0';
  if (ch == '.')
    for (ch = getchar(); ch <= '9' && ch >= '0'; ch = getchar(), t *= 0.1)
      x += t * (ch - '0');
  x *= f;
}
int b[maxn], c[maxn];
int m[M];
int main() {
  memset(b, -1, sizeof(b));
  memset(c, -1, sizeof(c));
  for (long long i = 2; i < 10000001; ++i) {
    if (m[i]) continue;
    m[i] = i;
    for (long long j = i * i; j < 10000001; j += i) {
      m[j] = i;
    }
  }
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) {
    int pre;
    read(pre);
    int j = m[pre];
    int A = 1;
    while (pre % j == 0) pre /= j, A *= j;
    if (pre != 1) b[i] = A, c[i] = pre;
  }
  for (int i = 1; i <= n; ++i) {
    printf("%d ", b[i]);
  }
  printf("\n");
  for (int j = 1; j <= n; ++j) {
    printf("%d ", c[j]);
  }
  return 0;
}
