#include <bits/stdc++.h>
using namespace std;
vector<long long> pr;
void sieve() {
  long long i, j;
  bitset<3200> bs;
  bs.set();
  bs[0] = bs[1] = 0;
  for (i = 2; i <= 3180; i++) {
    if (bs[i] == 1) {
      for (j = i * i; j <= 3180; j += i) bs[j] = 0;
      pr.push_back(i);
    }
  }
}
vector<long long> pf;
void p_fac(long long n) {
  long long ans = 1;
  for (long long i = 0; i < pr.size(); i++) {
    long long ans = 1;
    while (n % pr[i] == 0) {
      ans *= pr[i];
      n /= pr[i];
    }
    if (ans != 1) pf.push_back(ans);
  }
  if (n != 1) pf.push_back(n);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<pair<long long, long long>> ans(n);
  sieve();
  for (long long i = 0; i < n; i++) {
    pf.clear();
    long long a;
    cin >> a;
    p_fac(a);
    if (pf.size() == 1)
      ans[i].first = ans[i].second = -1;
    else {
      ans[i].first = pf[0];
      ans[i].second = a / ans[i].first;
    }
    cout << ans[i].first << ' ';
  }
  cout << '\n';
  for (long long i = 0; i < n; i++) cout << ans[i].second << " ";
}
