#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
bool mark[N];
vector<int> prime;
int ara[N], d1[N], d2[N];
void sieve() {
  prime.push_back(2);
  int root = (int)ceil(sqrt(N * 1.));
  for (int i = 4; i < N; i += 2) mark[i] = true;
  for (int i = 3; i < N; i += 2) {
    if (!mark[i]) {
      prime.push_back(i);
      if (i <= root) {
        for (int j = i * i; j <= N; j += i * 2) mark[j] = true;
      }
    }
  }
}
pair<int, int> ppf(int num) {
  vector<int> v;
  for (auto x : prime) {
    if (x * x > num) break;
    if (num % x == 0) {
      v.push_back(x);
      while (num % x == 0) num /= x;
    }
  }
  if (num != 1) v.push_back(num);
  if (v.size() > 1) {
    int a = v.back();
    int b = 1;
    v.pop_back();
    for (auto x : v) {
      b *= x;
    }
    return {a, b};
  }
  return {-1, -1};
}
int main(int argc, char const *argv[]) {
  sieve();
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &ara[i]);
    pair<int, int> ans = ppf(ara[i]);
    d1[i] = ans.first;
    d2[i] = ans.second;
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", d1[i]);
  }
  puts("");
  for (int i = 0; i < n; i++) {
    printf("%d ", d2[i]);
  }
  return 0;
}
