#include <bits/stdc++.h>
using namespace std;
void sieve(int n, int spf[]) {
  for (int i = 1; i < n; i++) spf[i] = i;
  for (int i = 4; i < n; i += 2) spf[i] = 2;
  for (int i = 3; i * i < n; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < n; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
int main() {
  int n;
  cin >> n;
  int max = 2;
  int num[n];
  for (int i = 0; i < n; i++) {
    cin >> num[i];
    if (num[i] > max) max = num[i];
  }
  int spf[max + 1];
  sieve(max + 1, spf);
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    int x = num[i];
    long long int other = 1;
    while (num[i] != 1) {
      int factor = spf[num[i]];
      while (num[i] % factor == 0) num[i] /= factor;
      other *= factor;
    }
    if (other == spf[x]) {
      a[i] = b[i] = -1;
    } else {
      a[i] = spf[x];
      b[i] = other / spf[x];
    }
  }
  for (int i = 0; i < n; i++) cout << a[i] << " ";
  cout << endl;
  for (int i = 0; i < n; i++) cout << b[i] << " ";
  cout << endl;
  return 0;
}
