#include <bits/stdc++.h>
using namespace std;
long long int binpow(long long int x, long long int y) {
  long long int z = 1;
  while (y > 0) {
    if (y % 2 == 1) z = (z * x) % 1000000007;
    x = (x * x) % 1000000007;
    y /= 2;
  }
  return z;
}
long long int inv(long long int x) { return binpow(x, 1000000007 - 2); }
long long int divide(long long int x, long long int y) { return x * inv(y); }
int n;
int l1[500005], l2[500005];
int fact[((int)1e7 + 1)];
void precompute() {
  for (int i = 2; i < ((int)1e7 + 1); i++) {
    if (fact[i]) continue;
    for (int j = i; j < ((int)1e7 + 1); j += i) fact[j] = i;
  }
}
void solve() {
  cin >> n;
  memset(fact, 0, sizeof(fact));
  precompute();
  for (int i = 1; i <= n; i++) {
    vector<int> p;
    int a;
    cin >> a;
    while (a > 1) {
      p.push_back(fact[a]);
      while (a % p.back() == 0) a /= p.back();
    }
    if (p.size() <= 1) {
      l1[i] = l2[i] = -1;
    } else {
      l1[i] = l2[i] = 1;
      for (int j = 0; j <= p.size() - 1; j++) {
        if (j < p.size() / 2)
          l1[i] *= p[j];
        else
          l2[i] *= p[j];
      }
    }
  }
  for (int i = 1; i <= n; i++) cout << l1[i] << (i < n ? " " : "\n");
  for (int i = 1; i <= n; i++) cout << l2[i] << (i < n ? " " : "\n");
}
int main() {
  int _ = 1;
  for (int t = 1; t <= _; t++) {
    solve();
  }
  return 0;
}
