#include <bits/stdc++.h>
using namespace std;
long long int visited[200001];
char c[1000][1000];
vector<long long int> v[200001];
long long int leaf[200001], leafc;
long long int dp[200001], ind[200001], dist[200001];
vector<pair<long long int, long long int>> at_leaf(200001);
long long int prime[10000001];
void SieveOfEratosthenes(long long int n) {
  for (long long int i = 1; i <= n; i++) prime[i] = 1;
  for (long long int p = 2; p * p <= n; p++) {
    if (prime[p] == 1) {
      for (long long int i = p * p; i <= n; i += p) {
        if (prime[i] == 1) prime[i] = p;
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  SieveOfEratosthenes(10000000);
  long long int n;
  cin >> n;
  long long int ans[n][2];
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    ans[i][0] = -1;
    ans[i][1] = -1;
    long long int q = 1;
    long long int temp = prime[a];
    if (temp != 1) {
      while (a % temp == 0) {
        a = a / temp;
        q = q * temp;
      }
      if (a != 1) {
        ans[i][0] = q;
        ans[i][1] = a;
      }
    }
  }
  for (long long int i = 0; i < n; i++) cout << ans[i][0] << " ";
  cout << endl;
  for (long long int i = 0; i < n; i++) cout << ans[i][1] << " ";
  cout << endl;
  return 0;
}
