#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
int n, a[maxn], f[10000007], prime[1000005], cnt;
int ans1[maxn], ans2[maxn];
template <class T>
void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    f |= (ch == '-');
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
inline void euler(int n) {
  f[1] = f[0] = 1;
  for (int i = 2; i <= n; i++) {
    if (!f[i]) prime[++cnt] = i;
    for (int j = 1; j <= cnt && i * prime[j] <= n; j++) {
      f[i * prime[j]] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  euler(1e7);
  for (int i = 1; i <= n; i++) {
    if (!f[a[i]])
      ans1[i] = ans2[i] = -1;
    else {
      int tp = f[a[i]];
      while (a[i] % tp == 0) a[i] /= tp;
      if (a[i] == 1)
        ans1[i] = ans2[i] = -1;
      else
        ans1[i] = a[i], ans2[i] = tp;
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", ans1[i]);
  puts("");
  for (int i = 1; i <= n; i++) printf("%d ", ans2[i]);
  return 0;
}
