#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long num[500005], used[10000005] = {0}, put[500005], put2[500005];
vector<long long> prime;
int main() {
  long long i, n;
  scanf("%lld", &n);
  for (i = 2; i <= 10000000; i++) {
    if (!used[i]) {
      prime.emplace_back(i);
      used[i] = i;
    }
    for (auto x : prime) {
      if (i * x > 10000000) break;
      used[i * x] = x;
      if (!(i % x)) break;
    }
  }
  for (i = 0; i < n; i++) scanf("%lld", &num[i]);
  for (i = 0; i < n; i++) {
    long long temp = num[i];
    while (num[i] % used[temp] == 0) num[i] /= used[temp];
    if (num[i] == 1)
      put[i] = put2[i] = -1;
    else {
      put[i] = used[temp];
      put2[i] = num[i];
    }
  }
  for (i = 0; i < n; i++) printf("%lld ", put[i]);
  putchar('\n');
  for (i = 0; i < n; i++) printf("%lld ", put2[i]);
}
