#include <bits/stdc++.h>
using namespace std;
long long int spf[10000004];
void precalc() {
  for (int i = 2; i <= 10000004; i++) {
    if (i % 2 == 0) {
      spf[i] = 2;
    } else if (spf[i] == 0) {
      long long int a = i;
      while (a < 10000001) {
        spf[a] = i;
        a = a + i;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, temp1, temp2, t, x, y, m, k, b, temp, a, q, d, p;
  precalc();
  cin >> n;
  vector<long long int> v(n), ans1(n), ans2(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    set<long long int> distinct;
    temp1 = temp2 = 1;
    temp = v[i];
    while (temp > 1) {
      if (spf[temp] >= 2) distinct.insert(spf[temp]);
      temp = temp / spf[temp];
    }
    if (distinct.size() == 1) {
      ans1[i] = ans2[i] = -1;
    } else {
      for (auto k = distinct.begin(); k != distinct.end(); k++) {
        if (k == distinct.begin()) {
          temp1 = *k;
        } else {
          temp2 = temp2 * (*k);
        }
      }
      ans1[i] = temp1;
      ans2[i] = temp2;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans1[i] << " ";
  }
  cout << endl;
  for (int i = 0; i < n; i++) {
    cout << ans2[i] << " ";
  }
}
