#include <bits/stdc++.h>
using namespace std;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
void setmax(T& a, T b) {
  a = max(a, b);
};
template <typename T>
void setmin(T& a, T b) {
  a = min(a, b);
};
template <typename T>
bool in(T lo, T v, T hi) {
  return lo <= v && v <= hi;
};
const int M = 5e5 + 10;
const int N = 1e7 + 10;
int small[N];
int u[M], v[M];
void solve(int i) {
  int n;
  cin >> n;
  int copy = n;
  int p = small[n];
  while (n % p == 0) n /= p;
  if (n == 1) {
    u[i] = v[i] = -1;
  } else {
    u[i] = n;
    v[i] = copy / n;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 2; i < N; i++) {
    if (small[i] == 0) {
      for (int j = i; j < N; j += i) {
        if (small[j] == 0) small[j] = i;
      }
    }
  }
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solve(i);
  }
  for (int i = 0; i < t; i++) cout << u[i] << " ";
  cout << '\n';
  for (int i = 0; i < t; i++) cout << v[i] << " ";
  cout << '\n';
  return 0;
}
