#include <bits/stdc++.h>
using namespace std;
bool pas = false;
vector<long long> primes;
vector<int> status;
bool check(long long state, long long pos) {
  return (status[state] & (1 << pos)) ? false : true;
}
int setBit(long long state, long long pos) {
  return status[state] |= (1 << pos);
}
void prime(long long n) {
  status.resize((n >> 5) + 2, 0);
  long long limit = sqrt(n + 1);
  if (n >= 2) primes.push_back(2);
  for (long long i = 3; i <= n; i += 2) {
    if (check(i >> 5, i & 31)) {
      primes.push_back(i);
      if (i > limit) continue;
      for (long long j = i * i; j <= n; j += (i << 1)) {
        status[j >> 5] = setBit(j >> 5, j & 31);
      }
    }
  }
}
int main() {
  int tc = 1;
  prime(10000000LL);
  while (tc--) {
    int n;
    scanf("%d", &n);
    long long x[n];
    for (long long &in : x) scanf("%lld", &in);
    long long d1 = 0, d2 = 0;
    vector<long long> ans1, ans2;
    for (int i = 0; i < n; i++) {
      pas = false;
      d1 = 1;
      d2 = 1;
      long long num = x[i];
      for (int j = 0; j < 447 && primes[j] <= num; j++) {
        if (num % primes[j] == 0) {
          if (pas)
            d2 *= primes[j];
          else {
            pas = true;
            d1 = primes[j];
          }
          while (num % primes[j] == 0) num /= primes[j];
        }
      }
      if (num != 1 && pas) d2 *= num;
      if (pas && d2 != 1 && x[i] % (d1 + d2)) {
        ans1.push_back(d1);
        ans2.push_back(d2);
      } else {
        ans1.push_back(-1);
        ans2.push_back(-1);
      }
    }
    for (int i = 0; i < ans1.size(); ++i) {
      printf("%lld", ans1[i]);
      printf(" ");
    }
    printf("\n");
    ;
    for (int i = 0; i < ans1.size(); ++i) {
      printf("%lld", ans2[i]);
      printf(" ");
    }
    printf("\n");
    ;
  }
}
