#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
bool arr[10000010];
long long prime[10000010];
vector<long long> primes;
void Eratosthenes(int N) {
  for (int i = 0; i < N; i++) {
    arr[i] = true;
    prime[i] = 1;
  }
  for (int i = 2; i < sqrt(N); i++) {
    if (arr[i]) {
      for (int j = 0; i * (j + 2) < N; j++) {
        arr[i * (j + 2)] = false;
        prime[i * (j + 2)] = i;
      }
    }
  }
  for (int i = 2; i < N; i++) {
    if (arr[i]) {
      primes.push_back(i);
      prime[i] = i;
    }
  }
}
int main() {
  Eratosthenes(10000005);
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> A(n);
  vector<pair<long long, long long>> ans(n);
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> A[i];
    if (prime[A[i]] == 1 || prime[A[i]] == A[i]) {
      ans[i].first = ans[i].second = -1;
    } else {
      long long res = A[i];
      long long p = prime[A[i]];
      while (res % p == 0) res /= p;
      if (res == 1) {
        ans[i].first = ans[i].second = -1;
      } else {
        ans[i].first = res;
        ans[i].second = A[i] / res;
      }
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) cout << ans[i].first << ' ';
  cout << endl;
  for (int i = (int)(0); i < (int)(n); i++) cout << ans[i].second << ' ';
  cout << endl;
  return 0;
}
