#include <bits/stdc++.h>
using namespace std;
long long newmod(long long a, long long b) { return ((a % b) + b) % b; }
long long powM(long long a, long long b, long long m) {
  a %= m;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long pow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
const long long N = 2e7;
long long spf[N];
void sieve() {
  for (int i = 0; i < N; ++i) spf[i] = i;
  for (int i = 2; i * i < N; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < N; j += i) {
        if (spf[j] == j) spf[j] = i;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<pair<long, long> > ans(n);
  sieve();
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    long long temp = a[i];
    set<long long> s;
    while (temp - 1) {
      s.insert(spf[temp]);
      temp /= spf[temp];
    }
    if (s.size() < 2) {
      ans[i].first = ans[i].second = -1;
    } else {
      long long val = 1LL;
      for (auto v : s) {
        val *= v;
      }
      long long d = *(s.begin());
      ans[i].first = d, ans[i].second = val / d;
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i].first << " ";
  }
  cout << "\n";
  for (int i = 0; i < n; ++i) {
    cout << ans[i].second << " ";
  }
  cout << "\n";
  return 0;
}
