#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  vector<long long> v1(n, 1);
  vector<long long> v2(n, 1);
  vector<long long> prime;
  vector<bool> is_prime((long long)sqrt(1e7) + 1, true);
  for (long long i = 2; i < is_prime.size(); i++) {
    if (is_prime[i]) {
      prime.push_back(i);
      long long k = 2;
      while (i * k < is_prime.size()) {
        is_prime[i * k++] = false;
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    long long xx = x;
    for (long long j = 0; j < prime.size(); j++) {
      if (prime[j] >= x) {
        break;
      }
      if (x % prime[j] == 0) {
        v1[i] = prime[j];
        while (x % prime[j] == 0) {
          x /= prime[j];
        }
        v2[i] = x;
        break;
      }
    }
    if (v2[i] == 1) {
      v1[i] = v2[i] = -1;
    }
  }
  for (long long x : v1) cout << x << ' ';
  cout << '\n';
  for (long long x : v2) cout << x << ' ';
  return 0;
}
