#include <bits/stdc++.h>
using namespace std;
struct Math {
  static const int N = 1e7 + 1;
  int i, j, k, pri[N], cnt, mpri[N];
  long long phi[N], mu[N];
  bool vis[N];
  inline void init() {
    cnt = 0;
    for (i = 2; i < N; ++i) {
      if (!vis[i]) pri[++cnt] = i, mpri[i] = i, phi[i] = i - 1, mu[i] = -1;
      for (j = 1; j <= cnt && i * pri[j] < N; ++j) {
        vis[k = i * pri[j]] = 1;
        mpri[k] = pri[j];
        if (i % pri[j] == 0) {
          phi[k] = phi[i] * pri[j], mu[k] = 0;
          break;
        } else
          phi[k] = phi[i] * (pri[j] - 1), mu[k] = -mu[i];
      }
    }
  }
} Mt;
int n, ans[2][500020];
inline void solve() {
  scanf("%d", &n);
  for (auto i = (1); i <= (n); ++i) {
    int a;
    scanf("%d", &a);
    long long o = Mt.mpri[a], p = 1;
    while (a % o == 0 && a != 1) p *= o, a /= o;
    if (a != 1 && p != 1)
      ans[1][i] = a, ans[2][i] = p;
    else
      ans[1][i] = -1, ans[2][i] = -1;
  }
  for (auto i = (1); i <= (n); ++i) printf("%d ", ans[1][i]);
  puts("");
  for (auto i = (1); i <= (n); ++i) printf("%d ", ans[2][i]);
  puts("");
}
int main() {
  int T = 1;
  Mt.init();
  while (T--) solve();
}
