#include <bits/stdc++.h>
using namespace std;
using VI = std::vector<int>;
using VVI = std::vector<VI>;
vector<int> d_arr_1;
vector<int> d_arr_2;
vector<int> prime_sieve;
vector<int> a_arr;
int n;
void sieve() {
  for (int i = 2; i < 1e7 + 1; i += 2) {
    prime_sieve[i] = 2;
  }
  for (int i = 3; i < 1e7 + 1; i += 2) {
    if (prime_sieve[i] == i) {
      for (int j = i * 2; j < 1e7 + 1; j += i) {
        if (prime_sieve[j] == j) prime_sieve[j] = i;
      }
    }
  }
}
void solve(int i) {
  int a = a_arr[i];
  int a2 = a;
  int div = prime_sieve[a];
  if (div == a) {
    d_arr_1.push_back(-1);
    d_arr_2.push_back(-1);
  } else {
    int counter = 0;
    int val = 1;
    while (a2 % div == 0) {
      counter += 1;
      val *= div;
      a2 /= div;
    }
    if (a2 == 1) {
      d_arr_1.push_back(-1);
      d_arr_2.push_back(-1);
    } else {
      d_arr_1.push_back(val);
      d_arr_2.push_back(a2);
    }
  }
}
int main() {
  cin >> n;
  a_arr = vector<int>(n);
  d_arr_1 = vector<int>(0);
  d_arr_2 = vector<int>(0);
  prime_sieve = vector<int>(1e7 + 1);
  for (int i = 1; i < 1e7 + 1; i++) {
    prime_sieve[i] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> a_arr[i];
  }
  sieve();
  for (int i = 0; i < n; i++) {
    solve(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cout << d_arr_1[i] << " ";
  }
  cout << d_arr_1[n - 1] << "\n";
  for (int i = 0; i < n - 1; i++) {
    cout << d_arr_2[i] << " ";
  }
  cout << d_arr_2[n - 1];
}
