#include <bits/stdc++.h>
using namespace std;
int prime[10000010 / 10], pn, mp[10000010];
void choto_divisibleprime(int x) {
  int i, j;
  for (i = 2; i <= x; i++) {
    if (!mp[i]) prime[++pn] = i, mp[i] = i;
    for (j = 1; prime[j] * i <= x; j++) {
      mp[prime[j] * i] = prime[j];
      if (i % prime[j] == 0) break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  choto_divisibleprime(10000010);
  int n;
  cin >> n;
  int arr[n + 4];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int d1[n + 3], d2[n + 3];
  for (int i = 0; i < n; i++) {
    d1[i] = d2[i] = -1;
    int x = arr[i];
    while (x % mp[arr[i]] == 0) x /= mp[arr[i]];
    if (x > 1) d1[i] = x, d2[i] = mp[arr[i]];
  }
  for (int i = 0; i < n; i++) cout << d1[i] << " ";
  cout << endl;
  for (int i = 0; i < n; i++) cout << d2[i] << " ";
  cout << endl;
  return 0;
}
