import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class d {

	public static void main(String[] args) throws Exception {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		sc = new FastScanner(in);
		int t = 1;

		while (t-- > 0) {
			sieve();
			int n = sc.nextInt();
			int [] arr = new int[n];
			int[] d1 = new int[n];
			int[] d2 = new int[n];
			Arrays.fill(d1, -1);
			Arrays.fill(d2, -1);
			for(int i = 0 ;i < n ;i++) {
				arr[i]=sc.nextInt();
			}
			for(int i = 0 ;i < n;i++) {
				ArrayList<Integer> prime = getFactorization(arr[i]);

				for(int d11 = 0 ; d11 < prime.size()  ;d11++) {
					for(int b = d11+1 ; b < prime.size()  ;b++) {
					    	int val = prime.get(d11)+prime.get(b);
					    	Collections.sort(prime);
							boolean ch = true;
					    	for(int c = 0 ; c <= b  ;c++) {
								if(val% prime.get(c)==0) {
									ch=false;
									break;
								}
							}
					    	if(ch) {
					    		d1[i] = prime.get(d11);
					    		d2[i] =prime.get(b);
					    	}

					}
				}
			}
			for(int i : d1)out.print(i +" ");
			out.println();
			for(int i : d2)out.print(i +" ");

		}

		out.flush();
	}

	static final int MAXN = 10000001;

    // stores smallest prime factor for every number
    static int spf[] = new int[MAXN];

    // Calculating SPF (Smallest Prime Factor) for every
    // number till MAXN.
    // Time Complexity : O(nloglogn)
    static void sieve()
    {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)

            // marking smallest prime factor for every
            // number to be itself.
            spf[i] = i;

        // separately marking spf for every even
        // number as 2
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;

        for (int i=3; i*i<MAXN; i++)
        {
            // checking if i is prime
            if (spf[i] == i)
            {
                // marking SPF for all numbers divisible by i
                for (int j=i*i; j<MAXN; j+=i)

                    // marking spf[j] if it is not
                    // previously marked
                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }

    // A O(log n) function returning primefactorization
    // by dividing by smallest prime factor at every step
    static ArrayList<Integer> getFactorization(int x)
    {
    	ArrayList<Integer> ret = new ArrayList<>();
        while (x != 1)
        {    if(ret.size()>0 && ret.get(ret.size()-1)==spf[x]) {

        }
        	 else
            ret.add(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }

	static BufferedReader in;
	static FastScanner sc;
	static PrintWriter out;

	static class FastScanner {
		BufferedReader in;
		StringTokenizer st;

		public FastScanner(BufferedReader in) {
			this.in = in;
		}

		public String nextToken() throws Exception {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(in.readLine());
			}
			return st.nextToken();
		}

		public int nextInt() throws Exception {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() throws Exception {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() throws Exception {
			return Double.parseDouble(nextToken());
		}
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;
        int MAXN = (int) (1e7 + 100);
        ArrayList<Integer> seive = PrimeUtils.seiveAsList(MAXN);
        int[] isPrime;
        int[] lastPrime;
        int[] primeCnt;

        public int[] seive(int n) {
            isPrime = new int[n + 1];
            lastPrime = new int[n + 1];
            primeCnt = new int[n + 1];
            Arrays.fill(isPrime, -1);

            isPrime[0] = isPrime[1] = 1;
            for (int i = 2; i * i <= n; i++) {
                if (isPrime[i] == -1) {
                    for (int j = 2; j <= n / i; j++) {
                        if (isPrime[i * j] == -1) {
                            isPrime[i * j] = i;
                        } else {
                            isPrime[i * j] = isPrime[i * j] * i;
                        }
                        lastPrime[i * j] = i;
                        primeCnt[i * j]++;
                    }
                }
            }
            return isPrime;
        }

        public long[] factorize(long n) {
            long a = -1, b = -1;

            for (int i = 0; i < seive.size(); i++) {
                long d = seive.get(i);
                boolean br = false;
                if (d * d > n) {
                    d = n;
                    br = true;
                    if (d == 1) break;
                }

                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    if (a == -1) {
                        a = d;
                    } else {
                        if (b != -1) {
                            a *= b;
                        }
                        b = d;
                    }
                }
                if (br) break;
            }
            return new long[]{a, b};
        }

        public long[] factorize2(int n) {
            long a = -1, b = -1;

            if (isPrime[n] == -1) {
                return new long[]{-1, -1};
            } else {
                if (primeCnt[n] < 2) {
                    return new long[]{-1, -1};
                }
                return new long[]{lastPrime[n], isPrime[n] / lastPrime[n]};
            }
        }

        public void solve() {
            int n = in.readInt();

            seive(MAXN);

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize2(a);
                long[] old = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        throw new RuntimeException();
                    }
                } else {
                    if (old[1] != -1) {
                        out.println(a);
                        return;
                    }
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class PrimeUtils {
        public static boolean[] seive(int n) {
            boolean[] isPrime = new boolean[n + 1];
            Arrays.fill(isPrime, true);

            isPrime[0] = isPrime[1] = false;
            for (int i = 2; i * i <= n; i++) {
                if (isPrime[i]) {
                    for (int j = 2; j <= n / i; j++) {
                        if (isPrime[i * j]) {
                            isPrime[i * j] = false;
                        }
                    }
                }
            }
            return isPrime;
        }

        public static ArrayList<Integer> seiveAsList(int n) {
            boolean[] isPrime = seive(n);
            ArrayList<Integer> res = new ArrayList<>();
            for (int i = 2; i <= n; i++) {
                if (isPrime[i]) {
                    res.add(i);
                }
            }
            return res;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;

        public static long[] factorize(long n) {
            long a = -1, b = -1;

            for (long d = 2; n > 1; ) {
                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    if (a == -1) {
                        a = d;
                    } else {
                        if (a == 2) {
                            b = d;
                        } else if (b == -1) {
                            b = d;
                        }
                    }
                }
                ++d;
                if (d * d > n) {
                    d = n;
                }
            }
            return new long[]{a, b};
        }

        public void solve() {
            int n = in.readInt();

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        throw new RuntimeException();
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;
        int MAXN = (int) (1e7 + 100);
        int[] isPrime;
        int[] lastPrime;
        int[] primeCnt;

        public int[] seive(int n) {
            isPrime = new int[n + 1];
            lastPrime = new int[n + 1];
            primeCnt = new int[n + 1];
            Arrays.fill(isPrime, -1);

            isPrime[0] = isPrime[1] = 1;
            for (int i = 2; i * i <= n; i++) {
                if (isPrime[i] == -1) {
                    for (int j = 2; j <= n / i; j++) {
                        if (isPrime[i * j] == -1) {
                            isPrime[i * j] = i;
                        } else {
                            isPrime[i * j] = isPrime[i * j] * i;
                        }
                        lastPrime[i * j] = i;
                        primeCnt[i * j]++;
                    }
                }
            }
            return isPrime;
        }

        public long[] factorize2(int n) {
            long a = -1, b = -1;

            if (isPrime[n] == -1) {
                return new long[]{-1, -1};
            } else {
                if (primeCnt[n] < 2) {
                    return new long[]{-1, -1};
                }
                return new long[]{lastPrime[n], isPrime[n] / lastPrime[n]};
            }
        }

        public void solve() {
            int n = in.readInt();

            seive(MAXN);

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize2(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        throw new RuntimeException();
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.TreeMap;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;

        public static TreeMap<Long, Integer> factorize(long n) {
            TreeMap<Long, Integer> factors = new TreeMap<>();
            for (long d = 2; n > 1; ) {
                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    factors.put(d, power);
                }
                ++d;
                if (d * d > n) {
                    d = n;
                }
            }
            return factors;
        }

        public void solve() {
            int n = in.readInt();
//        int[] a = in.readInts(n);

            int MAXN = (int) (1e7 + 100);

//        boolean[] seive = PrimeUtils.seive(MAXN);

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                TreeMap<Long, Integer> factorize = factorize(a);

                if (factorize.size() >= 2) {
                    res1[i] = factorize.firstKey().intValue();
                    res2[i] = factorize.lastKey().intValue();
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;
        int MAXN = (int) (1e7 + 100);
        int[] isPrime;
        int[] lastPrime;
        int[] primeCnt;

        public int[] seive(int n) {
            isPrime = new int[n + 1];
            lastPrime = new int[n + 1];
            primeCnt = new int[n + 1];
            Arrays.fill(isPrime, -1);

            isPrime[0] = isPrime[1] = 1;
            for (int i = 2; i <= n; i++) {
                if (isPrime[i] == -1) {
                    for (int j = 2; j <= n / i; j++) {
                        if (isPrime[i * j] == -1) {
                            isPrime[i * j] = i;
                        } else {
                            isPrime[i * j] = isPrime[i * j] * i;
                        }
                        lastPrime[i * j] = i;
                        primeCnt[i * j]++;
                    }
                }
            }
            return isPrime;
        }

        public long[] factorize2(int n) {
            long a = -1, b = -1;

            if (isPrime[n] == -1) {
                return new long[]{-1, -1};
            } else {
                if (primeCnt[n] < 2) {
                    return new long[]{-1, -1};
                }
                return new long[]{lastPrime[n], isPrime[n] / lastPrime[n]};
            }
        }

        public void solve() {
            int n = in.readInt();

            seive(MAXN);

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize2(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        throw new RuntimeException();
                    }
                } else {
//                long[] old = factorize(a);
//                if (old[1] != -1) {
//                    out.println(a);
//                    return;
//                }
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;

        public static long[] factorize(long n) {
            long a = -1, b = -1;

            int k = 0;
            for (long d = 2; n > 1; ) {
                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    k++;
                    if (a == -1) {
                        a = d;
                    } else {
                        b = d;
                    }
                }
                ++d;
                if (d * d > n) {
                    d = n;
                }
            }
            return new long[]{a, b};
        }

        public void solve() {
            int n = in.readInt();

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        res1[i] = res2[i] = -1;
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;
        int MAXN = (int) (1e7 + 100);
        int[] isPrime;
        int[] lastPrime;
        int[] primeCnt;

        public int[] seive(int n) {
            isPrime = new int[n + 1];
            lastPrime = new int[n + 1];
            primeCnt = new int[n + 1];
            Arrays.fill(isPrime, -1);

            isPrime[0] = isPrime[1] = 1;
            for (int i = 2; i * i <= n; i++) {
                if (isPrime[i] == -1) {
                    for (int j = 2; j <= n / i; j++) {
                        if (isPrime[i * j] == -1) {
                            isPrime[i * j] = i;
                        } else {
                            isPrime[i * j] = isPrime[i * j] * i;
                        }
                        lastPrime[i * j] = i;
                        primeCnt[i * j]++;
                    }
                }
            }
            return isPrime;
        }

        public long[] factorize2(int n) {
            long a = -1, b = -1;

            if (isPrime[n] == -1) {
                return new long[]{-1, -1};
            } else {
                if (primeCnt[n] < 2) {
                    return new long[]{-1, -1};
                }
                return new long[]{lastPrime[n], isPrime[n] / lastPrime[n]};
            }
        }

        public void solve() {
            int n = in.readInt();

            seive(MAXN);

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize2(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        throw new RuntimeException();
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;

        public static long[] factorize(long n) {
            long a = -1, b = -1;

            for (long d = 2; n > 1; ) {
                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    if (a == -1) {
                        a = d;
                    } else {
                        b = d;
                    }
                }
                ++d;
                if (d * d > n) {
                    d = n;
                }
            }
            return new long[]{a, b};
        }

        public void solve() {
            int n = in.readInt();

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        throw new RuntimeException();
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;
        int MAXN = (int) (1e7 + 100);
        ArrayList<Integer> seive = PrimeUtils.seiveAsList(MAXN);

        public long[] factorize(long n) {
            long a = -1, b = -1;

            for (int i = 0; i < seive.size(); i++) {
                long d = seive.get(i);
                boolean br = false;
                if (d * d > n) {
                    d = n;
                    br = true;
                    if (d == 1) break;
                }

                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    if (a == -1) {
                        a = d;
                    } else {
                        if (b != -1) {
                            a *= b;
                        }
                        b = d;
                    }
                }
                if (br) break;
            }
            return new long[]{a, b};
        }

        public void solve() {
            int n = in.readInt();

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        res1[i] = res2[i] = -1;
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class PrimeUtils {
        public static boolean[] seive(int n) {
            boolean[] isPrime = new boolean[n + 1];
            Arrays.fill(isPrime, true);

            isPrime[0] = isPrime[1] = false;
            for (int i = 2; i * i <= n; i++) {
                if (isPrime[i]) {
                    for (int j = 2; j <= n / i; j++) {
                        if (isPrime[i * j]) {
                            isPrime[i * j] = false;
                        }
                    }
                }
            }
            return isPrime;
        }

        public static ArrayList<Integer> seiveAsList(int n) {
            boolean[] isPrime = seive(n);
            ArrayList<Integer> res = new ArrayList<>();
            for (int i = 2; i <= n; i++) {
                if (isPrime[i]) {
                    res.add(i);
                }
            }
            return res;
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;

        public static long[] factorize(long n) {
            long a = -1, b = -1;

            for (long d = 2; n > 1; ) {
                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    if (a == -1) {
                        a = d;
                    } else {
                        if (b != -1) {
                            a *= b;
                        }
                        b = d;
                    }
                }
                ++d;
                if (d * d > n) {
                    d = n;
                }
            }
            return new long[]{a, b};
        }

        public void solve() {
            int n = in.readInt();

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];

                    if (Factorization.gcd(res1[i] + res2[i], a) != 1) {
                        res1[i] = res2[i] = -1;
                    }
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class Factorization {
        static public long gcd(long a, long b) {
            return a == 0 ? b : gcd(b % a, a);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Nikita Mikhailov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        DDvaDelitelya solver = new DDvaDelitelya();
        solver.solve(1, in, out);
        out.close();
    }

    static class DDvaDelitelya {
        int testNumber;
        InputReader in;
        OutputWriter out;

        public static long[] factorize(long n) {
            long a = -1, b = -1;

            for (long d = 2; n > 1; ) {
                int power = 0;
                while (n % d == 0) {
                    ++power;
                    n /= d;
                }
                if (power > 0) {
                    if (a == -1) {
                        a = d;
                    } else {
                        b = d;
                    }
                }
                ++d;
                if (d * d > n) {
                    d = n;
                }
            }
            return new long[]{a, b};
        }

        public void solve() {
            int n = in.readInt();
//        int[] a = in.readInts(n);

            int[] res1 = new int[n];
            int[] res2 = new int[n];
            for (int i = 0; i < n; i++) {
                int a = in.readInt();

                long[] factorize = factorize(a);

                if (factorize[1] != -1) {
                    res1[i] = (int) factorize[0];
                    res2[i] = (int) factorize[1];
                } else {
                    res1[i] = res2[i] = -1;
                }
            }

            for (int i = 0; i < n; i++) {
                out.print(res1[i] + " ");
            }
            out.println();
            for (int i = 0; i < n; i++) {
                out.print(res2[i] + " ");
            }
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            this.testNumber = testNumber;
            this.in = in;
            this.out = out;

            solve();
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void println() {
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.util.HashSet;

 public class STRING{
  final static int N;
  final static int di[];
 static {
 N =(int)( 1e7 + 5);
 di = new int[N];

 for (int i = 2; i * i < N; i++) {
   if (di[i]==0) {
     for (int j = i * i; j < N; j += i) {
       di[j] = i;
     }
   }
 }
 }

      public static void main( String args[]) {

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       Scanner sc = new Scanner(System.in);
      PrintWriter writer = new PrintWriter(System.out);
      int n = sc.nextInt();
      int arr[] = new int[n];
      int  arr1[][] = new int[n][2];
      for(int i=0;i<n;i++){
        arr[i] = sc.nextInt();
        arr1[i][0] = di[arr[i]];

        if(arr1[i][0] != 0){

         while(arr[i]%arr1[i][0]==0){
          arr[i] /= arr1[i][0];
          }

          if(arr[i]!=1){
            arr1[i][1] = arr[i];
          }
          else{
            arr1[i][1] = -1;arr1[i][0] = -1;
          }
        }
        else{
          arr1[i][1] = -1;arr1[i][0] = -1;
        }

      }
      for(int i =0;i<2;i++){
        for(int j=0;j<n;j++){
          writer.print(arr1[j][i]+" ");

        }
        writer.println();
        writer.flush();

      }

}

   public static String replace(String str, int index, char replace){
    if(str==null){
        return str;
    }else if(index<0 || index>=str.length()){
        return str;
    }
    char[] chars = str.toCharArray();
    chars[index] = replace;
    return String.valueOf(chars);
}
public static HashSet<Integer> primeFactors(int n)
{
    HashSet<Integer> h = new HashSet<Integer>();
    // Print the number of 2s that divide n
    while (n%2==0)
    {
        h.add(2);
        n /= 2;
    }

    // n must be odd at this point.  So we can
    // skip one element (Note i = i +2)
    for (int i = 3; i <= Math.sqrt(n); i+= 2)
    {

        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            h.add(i);
            n /= i;
        }
    }

    // This condition is to handle the case whien
    // n is a prime number greater than 2
    if(n>2)
      h.add(n);

   return h ;

 }
public static boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.util.HashSet;

public class STRING{
  final static int N;
  final static int di[];
 static {
 N =(int)( 1e7 + 5);
 di = new int[N];

 for (int i = 2; i * i < N; i++) {
   if (di[i]==0) {
     for (int j = i * i; j < N; j += i) {
       di[j] = i;
     }
   }
 }
 }

      public static void main( String args[]) {

      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       Scanner sc = new Scanner(System.in);
      PrintWriter writer = new PrintWriter(System.out);
      int n = sc.nextInt();
      int arr[] = new int[n];
      int  arr1[][] = new int[n][2];
      for(int i=0;i<n;i++){
        arr[i] = sc.nextInt();
        arr1[i][0] = di[i];
        if(di[i]!=0){
         while(arr[i]%di[i]==0){
          arr[i] /=di[i];
          }

          if(arr[i]!=1){
            arr1[i][1] = arr[i];
          }
          else{
            arr1[i][1] = -1;arr1[i][0] = -1;
          }
        }
        else{
          arr1[i][1] = -1;arr1[i][0] = -1;
        }

      }
      for(int i =0;i<2;i++){
        for(int j=0;j<n;j++){
          writer.print(arr1[j][i]+" ");

        }
        writer.println();
        writer.flush();

      }

}

   public static String replace(String str, int index, char replace){
    if(str==null){
        return str;
    }else if(index<0 || index>=str.length()){
        return str;
    }
    char[] chars = str.toCharArray();
    chars[index] = replace;
    return String.valueOf(chars);
}
public static HashSet<Integer> primeFactors(int n)
{
    HashSet<Integer> h = new HashSet<Integer>();
    // Print the number of 2s that divide n
    while (n%2==0)
    {
        h.add(2);
        n /= 2;
    }

    // n must be odd at this point.  So we can
    // skip one element (Note i = i +2)
    for (int i = 3; i <= Math.sqrt(n); i+= 2)
    {

        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            h.add(i);
            n /= i;
        }
    }

    // This condition is to handle the case whien
    // n is a prime number greater than 2
    if(n>2)
      h.add(n);

   return h ;

 }
public static boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.util.HashSet;

public class STRING{
    public static void main(final String args[]) throws IOException{
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       Scanner sc = new Scanner(System.in);
      PrintWriter writer = new PrintWriter(System.out);
      int n = sc.nextInt();
      int arr[] = new int[n];
      int  arr1[][] = new int[n][2];
      for (int[] row : arr1)
            Arrays.fill(row, -1);
      for(int i=0;i<n;i++){
        arr[i] = sc.nextInt();
          Integer [] s = primeFactors(arr[i]).stream().toArray(Integer[]::new);
        Arrays.sort(s);
        if(arr[i]%2!=0){
          if(s.length>=2){
            arr1[i][0] = s[0];
            arr1[i][1] = s[1];
          }
        }
        else{
          if(s.length>=2){
            arr1[i][0]=2;arr1[i][1]=1;
            for(int j=1;j<s.length;j++)
              arr1[i][1]*=s[j];
          }
        }

      }
      for(int i =0;i<2;i++){
        for(int j=0;j<n;j++){
          writer.print(arr1[j][i]+" ");
          writer.flush();
        }
        writer.println();
        writer.flush();

      }

}

   public static String replace(String str, int index, char replace){
    if(str==null){
        return str;
    }else if(index<0 || index>=str.length()){
        return str;
    }
    char[] chars = str.toCharArray();
    chars[index] = replace;
    return String.valueOf(chars);
}
public static HashSet<Integer> primeFactors(int n)
{
    HashSet<Integer> h = new HashSet<Integer>();
    // Print the number of 2s that divide n
    while (n%2==0)
    {
        h.add(2);
        n /= 2;
    }

    // n must be odd at this point.  So we can
    // skip one element (Note i = i +2)
    for (int i = 3; i <= Math.sqrt(n); i+= 2)
    {

        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            h.add(i);
            n /= i;
        }
    }

    // This condition is to handle the case whien
    // n is a prime number greater than 2
    if(n>2)
      h.add(n);

   return h ;

 }
public static boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.io.*;
import java.util.HashSet;

public class STRING{
    public static void main(final String args[]) throws IOException{
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       Scanner sc = new Scanner(System.in);
      PrintWriter writer = new PrintWriter(System.out);
      int n = sc.nextInt();
      int arr[] = new int[n];
      int  arr1[][] = new int[n][2];
      for (int[] row : arr1)
            Arrays.fill(row, -1);
      for(int i=0;i<n;i++){
        arr[i] = sc.nextInt();
          Integer [] s = primeFactors(arr[i]).stream().toArray(Integer[]::new);
        Arrays.sort(s);
        if(arr[i]%2!=0){
          if(s.length>=2){
            arr1[i][0] = s[0];
            arr1[i][1] = s[1];
          }
        }
        else{
          if(s.length>=2){
            arr1[i][0]=2;arr1[i][1]=1;
            for(int j=1;j<s.length;j++)
              arr1[i][1]*=s[j];
          }
        }

      }
      for(int i =0;i<2;i++){
        for(int j=0;j<n;j++){
          writer.print(arr1[j][i]+" ");

        }
        writer.println();
        writer.flush();

      }

}

   public static String replace(String str, int index, char replace){
    if(str==null){
        return str;
    }else if(index<0 || index>=str.length()){
        return str;
    }
    char[] chars = str.toCharArray();
    chars[index] = replace;
    return String.valueOf(chars);
}
public static HashSet<Integer> primeFactors(int n)
{
    HashSet<Integer> h = new HashSet<Integer>();
    // Print the number of 2s that divide n
    while (n%2==0)
    {
        h.add(2);
        n /= 2;
    }

    // n must be odd at this point.  So we can
    // skip one element (Note i = i +2)
    for (int i = 3; i <= Math.sqrt(n); i+= 2)
    {

        // While i divides n, print i and divide n
        while (n%i == 0)
        {
            h.add(i);
            n /= i;
        }
    }

    // This condition is to handle the case whien
    // n is a prime number greater than 2
    if(n>2)
      h.add(n);

   return h ;

 }
public static boolean isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int[] sd = sieveOfEratosthenes();
        final int n = in.nextInt();
        in.nextLine();
        final StringBuilder r1 = new StringBuilder();
        final StringBuilder r2 = new StringBuilder();
        for (int i = 0; i < n; i++) {
            int num = in.nextInt();
            final int div = sd[num];
            if (div == 0) {
                r1.append("-1 ");
                r2.append("-1 ");
            } else {
                while (num % div == 0) {
                    num /= div;
                }
                if (num != 1) {
                    r1.append(div + " ");
                    r2.append(num + " ");
                } else {
                    r1.append("-1 ");
                    r2.append("-1 ");
                }
            }
        }
        in.nextLine();
        System.out.println(r1);
        System.out.println(r2);
    }

    private static int[] sieveOfEratosthenes() {
        final int n = (int) 1e7;
        final boolean[] prime = new boolean[n + 1];
        final int[] smallestDiv = new int[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    if (smallestDiv[i] == 0) {
                        smallestDiv[i] = p;
                    }
                    prime[i] = false;
                }
            }
        }
        return smallestDiv;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final TreeSet<Integer> primes = sieveOfEratosthenes();
        final int n = in.nextInt();
        in.nextLine();
        final int[] r1 = new int[n];
        final int[] r2 = new int[n];
        Arrays.fill(r1, -1);
        Arrays.fill(r2, -1);
        for (int i = 0; i < n; i++) {
            final int num = in.nextInt();
            if (num % 2 != 0) {
                continue;
            }
            for (int p : primes) {
                if (p * 2 > num) {
                    break;
                }
                if (num % p == 0 && primes.contains(2 + p)) {
                    r1[i] = 2;
                    r2[i] = p;
                    break;
                }
            }
        }
        in.nextLine();
        for (int i = 0; i < n; i++) {
            System.out.print(r1[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            System.out.print(r2[i] + " ");
        }
        System.out.println();
    }

    private static TreeSet<Integer> sieveOfEratosthenes() {
        final int n = (int) 1e7 / 2;
        final boolean[] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    prime[i] = false;
                }
            }
        }
        final TreeSet<Integer> set = new TreeSet<>();
        for (int i = 3; i <= n; i++) {
            if (prime[i]) {
                set.add(i);
            }
        }
        return set;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final TreeSet<Integer> primes = sieveOfEratosthenes();
        final int n = in.nextInt();
        in.nextLine();
        final int[] r1 = new int[n];
        final int[] r2 = new int[n];
        Arrays.fill(r1, -1);
        Arrays.fill(r2, -1);
        for (int i = 0; i < n; i++) {
            final int num = in.nextInt();
            if (num % 2 != 0) {
                continue;
            }
            for (int p : primes) {
                if (p * 2 > num) {
                    break;
                }
                if (num % p == 0 && primes.contains(2 + p)) {
                    r1[i] = 2;
                    r2[i] = p;
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.print(r1[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            System.out.print(r2[i] + " ");
        }
        System.out.println();
    }

    private static TreeSet<Integer> sieveOfEratosthenes() {
        final int n = (int) 1e7 / 2;
        final boolean[] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    prime[i] = false;
                }
            }
        }
        final TreeSet<Integer> set = new TreeSet<>();
        for (int i = 3; i <= n; i++) {
            if (prime[i]) {
                set.add(i);
            }
        }
        return set;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int[] sd = sieveOfEratosthenes();
        final int n = in.nextInt();
        in.nextLine();
        final int[] r1 = new int[n];
        final int[] r2 = new int[n];
        Arrays.fill(r1, -1);
        Arrays.fill(r2, -1);
        for (int i = 0; i < n; i++) {
            int num = in.nextInt();
            final int div = sd[num];
            if (div == 0) {
                r1[i] = -1;
                r2[i] = -1;
            } else {
                while (num % div == 0) {
                    num /= div;
                }
                if (num != 1) {
                    r1[i] = div;
                    r2[i] = num;
                } else {
                    r1[i] = -1;
                    r2[i] = -1;
                }
            }
        }
        in.nextLine();
        for (int i = 0; i < n; i++) {
            System.out.print(r1[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            System.out.print(r2[i] + " ");
        }
        System.out.println();
    }

    private static int[] sieveOfEratosthenes() {
        final int n = (int) 1e7;
        final boolean[] prime = new boolean[n + 1];
        final int[] smallestDiv = new int[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    if (smallestDiv[i] == 0) {
                        smallestDiv[i] = p;
                    }
                    prime[i] = false;
                }
            }
        }
        return smallestDiv;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        TreeSet<Integer> primes = sieveOfEratosthenes();
        final int n = in.nextInt();
        in.nextLine();
        int[] r1 = new int[n];
        int[] r2 = new int[n];
        for (int i = 0; i < n; i++) {
            int num = in.nextInt();
            for (int p : primes) {
                if (num % 2 != 0 || p * 2 > num) {
                    r1[i] = -1;
                    r2[i] = -1;
                    break;
                }
                if (num % p == 0 && primes.contains(2 + p)) {
                    r1[i] = 2;
                    r2[i] = p;
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.print(r1[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            System.out.print(r2[i] + " ");
        }
        System.out.println();
    }

    private static TreeSet<Integer> sieveOfEratosthenes() {
        final int n = (int) 3162.2776601683795;
        final boolean[] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    prime[i] = false;
                }
            }
        }
        final TreeSet<Integer> set = new TreeSet<>();
        for (int i = 3; i <= n; i++) {
            if (prime[i]) {
                set.add(i);
            }
        }
        return set;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public final class C {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int[] sd = sieveOfEratosthenes();
        final int n = in.nextInt();
        in.nextLine();
        final int[] r1 = new int[n];
        final int[] r2 = new int[n];
        Arrays.fill(r1, -1);
        Arrays.fill(r2, -1);
        for (int i = 0; i < n; i++) {
            int num = in.nextInt();
            final int div = sd[num];
            if (div == 0) {
                r1[i] = -1;
                r2[i] = -1;
            } else {
                while (num % div == 0) {
                    num /= div;
                }
                if (num != 1) {
                    r1[i] = div;
                    r2[i] = num;
                } else {
                    r1[i] = -1;
                    r2[i] = -1;
                }
            }
        }
        in.nextLine();
        for (int i = 0; i < n; i++) {
            System.out.print(r1[i] + " ");
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            System.out.print(r2[i] + " ");
        }
        System.out.println();
    }

    private static int[] sieveOfEratosthenes() {
        final int n = (int) 1e7 / 2;
        final boolean[] prime = new boolean[n + 1];
        final int[] smallestDiv = new int[n + 1];
        Arrays.fill(prime, true);
        for (int p = 2; p * p <= n; p++) {
            if (prime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    if (smallestDiv[i] == 0) {
                        smallestDiv[i] = p;
                    }
                    prime[i] = false;
                }
            }
        }
        return smallestDiv;
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = f.nextInt();
		int[] a = new int[n], b = new int[n];
		HashMap<Integer,Integer> hm = new HashMap<>();
		for(int asdf = 0; asdf < n; asdf++) {
			a[asdf] = b[asdf] = -1;
			int k = f.nextInt();
			if(hm.containsKey(k)) {
				a[asdf] = a[hm.get(k)];
				b[asdf] = b[hm.get(k)];
			}
			hm.put(k,asdf);
			for(int i = 2; i*i <= k; i++) {
				if(k%i == 0) {
					int p = 1;
					int q = k;
					while(q%i == 0) {
						q /= i;
						p *= i;
					}
					if(q != 1) {
						a[asdf] = q;
						b[asdf] = p;
					}
					break;
				}
			}
		}
		for(int i = 0; i < n; i++) out.print(a[i] + " ");
		out.println();
		for(int i = 0; i < n; i++) out.print(b[i] + " ");
		out.println();
		out.flush();
///
		out.flush();
	}
///
	static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = f.nextInt();
		int[] a = new int[n], b = new int[n];
		int[] s = new int[10000001];
		for(int i = 2; i < s.length; i++) {
			if(s[i] != 0) continue;
			for(int j = i; j < s.length; j += i) s[j] = i;
		}
		for(int asdf = 0; asdf < n; asdf++) {
			a[asdf] = b[asdf] = -1;
			int k = f.nextInt();
			int i = s[k];
			int p = 1;
			int q = k;
			while(q%i == 0) {
				q /= i;
				p *= i;
			}
			if(q != 1) {
				a[asdf] = q;
				b[asdf] = p;
			}
		}
		for(int i = 0; i < n; i++) out.print(a[i] + " ");
		out.println();
		for(int i = 0; i < n; i++) out.print(b[i] + " ");
		out.println();
		out.flush();
///
		out.flush();
	}
///
	static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class template {
	public static void main(String[] args) throws Exception {
		new template().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = f.nextInt();
		int[] a = new int[n], b = new int[n];
		HashMap<Integer,Integer> hm = new HashMap<>();
		for(int asdf = 0; asdf < n; asdf++) {
			a[asdf] = b[asdf] = -1;
			int k = f.nextInt();
			if(hm.containsKey(k)) {
				a[asdf] = a[hm.get(k)];
				b[asdf] = b[hm.get(k)];
				continue;
			}
			hm.put(k,asdf);
			for(int i = 2; i*i <= k; i++) {
				if(k%i == 0) {
					int p = 1;
					int q = k;
					while(q%i == 0) {
						q /= i;
						p *= i;
					}
					if(q != 1) {
						a[asdf] = q;
						b[asdf] = p;
					}
					break;
				}
			}
		}
		for(int i = 0; i < n; i++) out.print(a[i] + " ");
		out.println();
		for(int i = 0; i < n; i++) out.print(b[i] + " ");
		out.println();
		out.flush();
///
		out.flush();
	}
///
	static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}


import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;

public class D {
	public static void main(String[] args) throws Exception {
		new D().run();
	}
	public void run() throws Exception {
		FastScanner f = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = f.nextInt();
		int MAX = (1 << 18) - 1;
		int[][] mat = new int[3][3];
		mat[0][0] = mat[2][1] = mat[1][2] = MAX;
		mat[0][1] = mat[0][2] = mat[2][2] = n;
		mat[1][0] = mat[1][1] = mat[2][0] = MAX-n;
		out.println("3 3");
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) out.print(mat[i][j] + " ");
			out.println();
		}
///
		out.flush();
	}
///
    static class FastScanner {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public FastScanner() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
        public String nextLine() {
        	try {
        		return reader.readLine();
        	} catch(IOException e) {
        		throw new RuntimeException(e);
        	}
        }
    }
}