#include <bits/stdc++.h>
using namespace std;
ifstream fin("input");
void init() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
}
const int mx = 5e5 + 100;
const int nx = 1e7 + 100;
int n, v[mx], spf[nx];
void read() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
}
void preprocess() {
  spf[1] = 1;
  for (int i = 2; i < nx; i++) {
    spf[i] = i;
  }
  for (int i = 4; i < nx; i += 2) {
    spf[i] = 2;
  }
  for (int i = 3; i * i < nx; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < nx; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }
}
int gcd(int a, int b) {
  int c;
  while (b) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
std::pair<int, int> ans(int x) {
  int k = spf[x];
  while (x % k == 0) {
    x /= k;
  }
  if (x == 1) return {-1, -1};
  return {k, x};
}
void solve() {
  preprocess();
  vector<std::pair<int, int>> result;
  for (int i = 0; i < n; i++) {
    result.push_back(ans(v[i]));
  }
  for (int i = 0; i < n; i++) {
    cout << result[i].first << " ";
  }
  cout << endl;
  for (int i = 0; i < n; i++) {
    cout << result[i].second << " ";
  }
}
int main() {
  init();
  read();
  solve();
  return 0;
}
