#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
void sieve() {
  int i, j;
  bitset<3201> bs;
  bs.set();
  bs[0] = bs[1] = 0;
  for (i = 2; i <= 3200; i++) {
    if (bs[i] == 1) {
      for (j = i * i; j <= 3200; j += i) bs[j] = 0;
      primes.push_back(i);
    }
  }
}
vector<int> pf;
void p_factorize(int N) {
  for (int i = 0; i < primes.size(); i++) {
    int Count = 1;
    while (N % primes[i] == 0) {
      N /= primes[i];
      Count *= primes[i];
    }
    if (Count != 1) pf.push_back(Count);
  }
  if (N != 1) pf.push_back(N);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, a;
  cin >> n;
  vector<pair<int, int> > ans(n);
  sieve();
  for (i = 0; i < n; i++) {
    pf.clear();
    cin >> a;
    p_factorize(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 (i = 0; i < n; i++) cout << ans[i].second << ' ';
}
