#include <bits/stdc++.h>
using namespace std;
const int mx = 10000005;
const int mx2 = 500005;
int a[mx2];
int b[mx2];
bool vis[mx];
vector<int> prime;
int main() {
  int i, j;
  for (i = 4; i < mx; i += 2) vis[i] = 1;
  for (i = 3; i * i < mx; i += 2) {
    if (!vis[i]) {
      for (j = i * i; j < mx; j += 2 * i) vis[j] = 1;
    }
  }
  prime.push_back(2);
  for (i = 3; i < mx; i += 2)
    if (!vis[i]) prime.push_back(i);
  int sq, now, k, num, sum, n, x;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &num);
    x = num;
    if (!vis[num]) {
      a[i] = b[i] = -1;
      continue;
    }
    sq = sqrt(num);
    now = 1;
    for (j = 0; prime[j] <= sq && now == 1; j++) {
      while (num % prime[j] == 0) {
        num = num / prime[j];
        now = now * prime[j];
      }
    }
    k = x / now;
    if (now > 1 && k > 1) {
      a[i] = now;
      b[i] = k;
    } else {
      a[i] = b[i] = -1;
    }
  }
  for (i = 0; i < n; i++) {
    printf("%d ", a[i]);
  }
  printf("\n");
  for (i = 0; i < n; i++) {
    printf("%d ", b[i]);
  }
  printf("\n");
  return 0;
}
