#include <bits/stdc++.h>
using namespace std;
long long fpow(long long x, long long b, long long p) {
  long long res = 1;
  for (; b; b >>= 1) {
    if (b & 1) res = res * x % p;
    x = x * x % p;
  }
  return res % p;
}
const int maxn = 1e7 + 10;
bool vp[maxn];
int p[maxn];
void pri() {
  for (int i = 2; i < maxn; i++) {
    if (!vp[i]) p[++p[0]] = i;
    for (int j = 1; j <= p[0] && i * p[j] < maxn; j++) {
      vp[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}
pair<int, int> ck(int x) {
  vector<int> v;
  int c = x;
  for (int i = 1; i <= p[0]; i++) {
    if (p[i] > sqrt(x)) break;
    if (x % p[i] == 0) {
      int cp = 1;
      while (x % p[i] == 0) {
        x /= p[i];
        cp *= p[i];
      }
      v.push_back(cp);
    }
  }
  if (x > 1) {
    v.push_back(x);
  }
  if (v.size() >= 2) return {v[0], c / v[0]};
  return {-1, -1};
}
pair<int, int> ans[500010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  pri();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ans[i] = ck(x);
  }
  for (int i = 1; i <= n; i++) cout << ans[i].first << ' ';
  cout << '\n';
  for (int i = 1; i <= n; i++) cout << ans[i].second << ' ';
}
