#include <bits/stdc++.h>
using namespace std;
long long int n, a, k, res, total;
int criba[3202], q;
vector<long long int> primos, r1, r2;
bool ya;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  for (int i = (2); i <= (56); i++) {
    if (criba[i] == 0) {
      primos.push_back(i);
      for (q = i * i; q <= 3200; q += i) criba[q] = 1;
    }
  }
  for (int i = (57); i <= (3200); i++)
    if (criba[i] == 0) primos.push_back(i);
  cin >> n;
  for (int i = (1); i <= (n); i++) {
    cin >> a;
    ya = false;
    for (auto p : primos) {
      if (p >= a) {
        r1.push_back(-1);
        r2.push_back(-1);
        ya = true;
        break;
      }
      if (a % p == 0) {
        k = a;
        res = 1;
        while (k % p == 0) {
          k /= p;
          res *= p;
        }
        if (k > 1) {
          r1.push_back(k);
          r2.push_back(res);
        } else {
          r1.push_back(-1);
          r2.push_back(-1);
        }
        ya = true;
        break;
      }
    }
    if (!ya) {
      r1.push_back(-1);
      r2.push_back(-1);
    }
  }
  for (auto x : r1) cout << x << ' ';
  cout << "\n";
  for (auto x : r2) cout << x << ' ';
}
