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[] a = new int[n], b = new int[n];
		for(int asdf = 0; asdf < n; asdf++) {
			a[asdf] = b[asdf] = -1;
			int k = f.nextInt();
			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();
	}
    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.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);

	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];
	static final int MAXN = 10000007;

	// 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 Vector<Integer> getFactorization(int x) {
		Vector<Integer> ret = new Vector<>();
		while (x != 1) {
			ret.add(spf[x]);
//			if(spf[x]==0)
//				return ret;
			x = x / spf[x];
		}
		return ret;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		 sieve();
		int n = sc.nextInt();
		int res[] = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = sc.nextInt();
		}
		int ans[][] = new int[n][2];
		for (int i = 0; i < res.length; i++) {
			Vector<Integer> p = getFactorization(res[i]);
			if (p.size() >= 2 && p.get(0)!=p.get(p.size()-1)) {
				ans[i][0] = p.get(0);
				ans[i][1] = p.get(p.size()-1);

			} else {
				ans[i][0] = -1;
				ans[i][1] = -1;
			}
		}

		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][0] + " ");
		}
		pr.println();
		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][1] + " ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);
	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];
	static boolean prime[] = new boolean[10000007];
	static int spf[] = new int[10000007];

	public static void sieveOfEratosthenes(int n) {
		for (int i = 2; i < n; i++)
			prime[i] = true;
		for (int p = 2; p * p <= n; p++) {

			if (prime[p] == true) {

				for (int i = p * p; i <= n; i += p) {
					prime[i] = false;
					spf[i] = p;
				}
			}
		}
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		int n = sc.nextInt();
		int arr[] = sc.nextIntArray(n);
		int res[][] = new int[n][2];
		sieveOfEratosthenes(10000005);
		for (int i = 0; i < n; i++) {
			if (spf[arr[i]] == 0) {
				res[i][0] = -1;
				res[i][1] = -1;

			} else {
				int p = spf[arr[i]];
				int a = arr[i];
				while (a % p == 0) {
					a /= p;
				}
				if (a == 1) {
					res[i][0] = -1;
					res[i][1] = -1;
				} else {
					res[i][0] = a;
					res[i][1] = (arr[i] / a);
				}
			}
		}
		for (int i = 0; i < n; i++) {
			pr.print(res[i][0] + " ");
		}
		pr.println();
		for (int i = 0; i < n; i++) {
			pr.print(res[i][1] + " ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);

	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];
	static final int MAXN = 10000007;

	// 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 Vector<Integer> getFactorization(int x) {
		Vector<Integer> ret = new Vector<>();
		while (x != 1) {
			ret.add(spf[x]);
//			if(spf[x]==0)
//				return ret;
			x = x / spf[x];
		}
		return ret;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		 sieve();
		int n = sc.nextInt();
		int res[] = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = sc.nextInt();
		}
		int ans[][] = new int[n][2];
		for (int i = 0; i < res.length; i++) {
			Vector<Integer> p = getFactorization(res[i]);
			int f=0;
			int l=p.size();
			for(int k=0;k<l;k++)
			{
				if((res[i]/p.get(k)!=1))
				p.add(res[i]/p.get(k));
			}
			for(int k=0;k<p.size();k++)
			{
				for(int j=k+1;j<p.size();j++)
				{
					if(p.get(k)!=p.get(j) && gcd(res[i],p.get(k)+p.get(j))==1)
					{
						f=1;
						ans[i][0] = p.get(k);
						ans[i][1] = p.get(j);
					}
				}
			}
			if(f==0)
			{
				ans[i][0] = -1;
				ans[i][1] = -1;
			}
		}

		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][0] + " ");
		}
		pr.println();
		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][1] + " ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);

	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];
	static final int MAXN = 10000007;

	// 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 Vector<Integer> getFactorization(int x) {
		Vector<Integer> ret = new Vector<>();
		while (x != 1) {
			ret.add(spf[x]);
//			if(spf[x]==0)
//				return ret;
			x = x / spf[x];
		}
		return ret;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		 sieve();
		int n = sc.nextInt();
		int res[] = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = sc.nextInt();
		}
		int ans[][] = new int[n][2];
		for (int i = 0; i < res.length; i++) {
			Vector<Integer> p = getFactorization(res[i]);
			int f=0;
			for(int k=0;k<p.size();k++)
			{
				for(int j=k+1;j<p.size();j++)
				{
					if(p.get(k)!=p.get(j) && gcd(res[i],p.get(k)+p.get(j))==1)
					{
						f=1;
						ans[i][0] = p.get(k);
						ans[i][1] = p.get(j);
					}
				}
			}
			if(f==0)
			{
				ans[i][0] = -1;
				ans[i][1] = -1;
			}
		}

		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][0] + " ");
		}
		pr.println();
		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][1] + " ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);

	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];
	static final int MAXN = 10000007;

	// 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 Vector<Integer> getFactorization(int x) {
		Vector<Integer> ret = new Vector<>();
		while (x != 1) {
			ret.add(spf[x]);
//			if(spf[x]==0)
//				return ret;
			x = x / spf[x];
		}
		return ret;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		 sieve();
		int n = sc.nextInt();
		int res[] = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = sc.nextInt();
		}
		int ans[][] = new int[n][2];
		for (int i = 0; i < res.length; i++) {
			Vector<Integer> p = getFactorization(res[i]);
			int f=0;
			int l=p.size();
			for(int k=0;k<l;k++)
			{
				p.add(res[i]/p.get(k));
			}
			for(int k=0;k<p.size();k++)
			{
				for(int j=k+1;j<p.size();j++)
				{
					if(p.get(k)!=p.get(j) && gcd(res[i],p.get(k)+p.get(j))==1)
					{
						f=1;
						ans[i][0] = p.get(k);
						ans[i][1] = p.get(j);
					}
				}
			}
			if(f==0)
			{
				ans[i][0] = -1;
				ans[i][1] = -1;
			}
		}

		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][0] + " ");
		}
		pr.println();
		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][1] + " ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);

	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		int arr[][]=new int[10000007][2];

		for(int i=2;i<=10000000;i++)
		{
			if(arr[i][0]==0){
			for(int j=i+i;j<=10000000;j+=i)
			{
				if(arr[j][0]==0)
					arr[j][0]=i;
				else
				arr[j][1]=i;
			}
			}
		}
		int n=sc.nextInt();
		int res[]=new int[n];
		for(int i=0;i<n;i++)
		{
			res[i]=sc.nextInt();
		}
		for(int i=0;i<res.length;i++)
		{
			if(arr[res[i]][0]!=0 && arr[res[i]][1]!=0 )
				pr.print(arr[res[i]][0]+" ");
			else
				pr.print("-1 ");
		}
		pr.println();
		for(int i=0;i<res.length;i++)
		{
			if(arr[res[i]][0]!=0 && arr[res[i]][1]!=0 )
				pr.print(arr[res[i]][1]+" ");
			else
				pr.print("-1 ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
	static final int INF = (int) (1e9 + 10);
	static final long MOD = (int) (1e9 + 7);
	static final int N = (int) (4e5 + 5);

	// static ArrayList<Integer>[] graph;
	// static boolean visited[];
	// static long size[];
	static final int MAXN = 10000007;

	// 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 Vector<Integer> getFactorization(int x) {
		Vector<Integer> ret = new Vector<>();
		while (x != 1) {
			ret.add(spf[x]);
			// if(spf[x]==0)
			// return ret;
			x = x / spf[x];
		}
		return ret;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		FastReader sc = new FastReader();
		PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// Scanner scn = new Scanner(System.in);
		//
		sieve();
		int n = sc.nextInt();
		int res[] = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = sc.nextInt();
		}
		int ans[][] = new int[n][2];
		for (int i = 0; i < res.length; i++) {
			Vector<Integer> p = getFactorization(res[i]);
			int f = 0;
			int l = p.size();
			HashSet<Integer> h = new HashSet<>();
			for (int k = 0; k < l; k++) {
				if ((res[i] / p.get(k) != 1)) {
					h.add(res[i] / p.get(k));
					h.add(p.get(k));
				}
			}
			int arm[]=new int[h.size()];
			int c=0;
			for(int j:h)
			{
				arm[c++]=j;
			}
			for (int k = 0; k < arm.length; k++) {
				for (int j = k + 1; j < arm.length; j++) {
					if (arm[k] != arm[j] && gcd(res[i], arm[k] + arm[j]) == 1) {
						f = 1;
						ans[i][0] = arm[k];
						ans[i][1] = arm[j];
					}
				}
			}
			if (f == 0) {
				ans[i][0] = -1;
				ans[i][1] = -1;
			}
		}

		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][0] + " ");
		}
		pr.println();
		for (int i = 0; i < res.length; i++) {
			pr.print(ans[i][1] + " ");
		}
		//
		// coded to perfection by Rohan Mukhija
		pr.flush();
		pr.close();
	}

	/*
	 * Template From Here
	 */
	public static class Pair implements Comparable<Pair> {
		int u;
		int v;

		Pair(int u, int v) {
			this.u = u;
			this.v = v;

		}

		public int compareTo(Pair compareEdge) {
			return Long.compare(this.v, compareEdge.v);
		}
	};

	private static boolean possible(long[] arr, int[] f, long mid, long k) {
		long c = 0;

		for (int i = 0; i < arr.length; i++) {
			if ((arr[i] * f[f.length - i - 1]) > mid) {
				c += (arr[i] - (mid / f[f.length - i - 1]));
			}
		}
		// System.out.println(mid+" "+c);
		if (c <= k)
			return true;
		return false;
	}

	static void sort(long[] a) {
		ArrayList<Long> l = new ArrayList<>();
		for (long i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	static void sort(int[] a) {
		ArrayList<Integer> l = new ArrayList<>();
		for (int i : a)
			l.add(i);
		Collections.sort(l);
		for (int i = 0; i < a.length; i++)
			a[i] = l.get(i);
	}

	public static int lowerBound(ArrayList<Integer> array, int length, long value) {
		int low = 0;
		int high = length;
		while (low < high) {
			final int mid = (low + high) / 2;
			if (value <= array.get(mid)) {
				high = mid;
			} else {
				low = mid + 1;
			}
		}
		return low;
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

	static long gcd(long a, long b) {
		if (a == 0)
			return b;
		return gcd(b % a, a);
	}

	static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	public static void sortbyColumn(int[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<int[]>() {

			@Override
			// Compare values according to columns
			public int compare(final int[] entry1, final int[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Integer(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	public static void sortbyColumn(double[][] att, int col) {
		// Using built-in sort function Arrays.sort
		Arrays.sort(att, new Comparator<double[]>() {

			@Override
			// Compare values according to columns
			public int compare(final double[] entry1, final double[] entry2) {

				// To sort in descending order revert
				// the '>' Operator
				// if (entry1[col] > entry2[col])
				// return 1;
				// else //(entry1[col] >= entry2[col])
				// return -1;
				return new Double(entry1[col]).compareTo(entry2[col]);
				// return entry1[col].
			}
		}); // End of function call sort().
	}

	static class pair {
		int V, I;

		pair(int v, int i) {
			V = v;
			I = i;
		}
	}

	public static int[] swap(int data[], int left, int right) {
		int temp = data[left];
		data[left] = data[right];
		data[right] = temp;
		return data;
	}

	public static int[] reverse(int data[], int left, int right) {
		while (left < right) {
			int temp = data[left];
			data[left++] = data[right];
			data[right--] = temp;
		}
		return data;
	}

	public static boolean findNextPermutation(int data[]) {
		if (data.length <= 1)
			return false;

		int last = data.length - 2;
		while (last >= 0) {
			if (data[last] < data[last + 1]) {
				break;
			}
			last--;
		}
		if (last < 0)
			return false;

		int nextGreater = data.length - 1;
		for (int i = data.length - 1; i > last; i--) {
			if (data[i] > data[last]) {
				nextGreater = i;
				break;
			}
		}
		data = swap(data, nextGreater, last);
		data = reverse(data, last + 1, data.length - 1);
		return true;
	}

	static long ncr(long a, long b) {
		if (b > a - b)
			return ncr(a, a - b);
		long ansMul = 1;
		long ansDiv = 1;
		for (int i = 0; i < b; i++) {
			ansMul *= (a - i);
			ansDiv *= (i + 1);
			ansMul %= MOD;
			ansDiv %= MOD;
		}

		long ans = ansMul * power(ansDiv, MOD - 2, MOD) % MOD;

		return ans;
	}

	static long __gcd(long n1, long n2) {
		long gcd = 1;

		for (int i = 1; i <= n1 && i <= n2; ++i) {
			// Checks if i is factor of both integers
			if (n1 % i == 0 && n2 % i == 0) {
				gcd = i;
			}
		}
		return gcd;
	}

	static long power(long prev, long n2, long mod2) {
		long res = 1;

		prev = prev % mod2;

		if (prev == 0)
			return 0;
		while (n2 > 0) {

			if ((n2 & 1) == 1)
				res = (res * prev) % mod2;

			n2 = n2 >> 1;
			prev = (prev * prev) % mod2;
		}
		return res;
	}

	static long modInverse(long fac2, int p) {
		return power(fac2, p - 2, p);
	}

	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;
	}

	public static BigInteger lcmm(String a, String b) {
		BigInteger s = new BigInteger(a);
		BigInteger s1 = new BigInteger(b);
		BigInteger mul = s.multiply(s1);
		BigInteger gcd = s.gcd(s1);
		BigInteger lcm = mul.divide(gcd);
		return lcm;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    public void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int[] minPrimefactorOf = new int[10000001];
        for (int i = 2; i <= 10000000; i++) {
            if (minPrimefactorOf[i] == 0) {
                minPrimefactorOf[i] = i;
                for (int j = 2 * i; j <= 10000000; j += i) {
                    if (minPrimefactorOf[i] == 0) minPrimefactorOf[j] = i;
                }
            }
        }

        int n = Integer.parseInt(f.readLine());
        int[][] res = new int[n][2];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(tokenizer.nextToken());
            int firstPrime = minPrimefactorOf[num];
            int first = 1;
            int second = 1;
            while (minPrimefactorOf[num] == firstPrime) {
                first *= firstPrime;
                num /= firstPrime;
            }

            if (num == 1) {
                res[i][0] = -1;
                res[i][1] = -1;
                continue;
            }

            while (num > 1) {
                second *= minPrimefactorOf[num];
                num /= minPrimefactorOf[num];
            }

            res[i][0] = first;
            res[i][1] = second;
        }

        for (int i = 0; i < 2; i++) {
            out.print(res[0][i]);
            for (int j = 1; j < n; j++) {
                out.print(" ");
                out.print(res[j][i]);
            }
            out.println();
        }

        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    public void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int[] minPrimefactorOf = new int[10000001];
        for (int i = 2; i <= 10000000; i++) {
            if (minPrimefactorOf[i] == 0) {
                minPrimefactorOf[i] = i;
                for (int j = 2 * i; j <= 10000000; j += i) {
                    if (minPrimefactorOf[j] == 0) minPrimefactorOf[j] = i;
                }
            }
        }

        int n = Integer.parseInt(f.readLine());
        int[][] res = new int[n][2];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(tokenizer.nextToken());
            int firstPrime = minPrimefactorOf[num];
            int first = 1;
            int second = 1;
            while (minPrimefactorOf[num] == firstPrime) {
                first *= firstPrime;
                num /= firstPrime;
            }

            if (num == 1) {
                res[i][0] = -1;
                res[i][1] = -1;
                continue;
            }

            while (num > 1) {
                second *= minPrimefactorOf[num];
                num /= minPrimefactorOf[num];
            }

            res[i][0] = first;
            res[i][1] = second;
        }

        for (int i = 0; i < 2; i++) {
            out.print(res[0][i]);
            for (int j = 1; j < n; j++) {
                out.print(" ");
                out.print(res[j][i]);
            }
            out.println();
        }

        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    public void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int[] minPrimefactorOf = new int[10000001];
        for (int i = 2; i <= 10000000; i++) {
            if (minPrimefactorOf[i] == 0) {
                minPrimefactorOf[i] = i;
                for (int j = 2 * i; j <= 10000000; j += i) {

                    minPrimefactorOf[j] = i;
                }
            }
        }

        int n = Integer.parseInt(f.readLine());
        int[][] res = new int[n][2];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(tokenizer.nextToken());
            int firstPrime = minPrimefactorOf[num];
            int first = 1;
            int second = 1;
            while (minPrimefactorOf[num] == firstPrime) {
                first *= firstPrime;
                num /= firstPrime;
            }

            if (num == 1) {
                res[i][0] = -1;
                res[i][1] = -1;
                continue;
            }

            while (num > 1) {
                second *= minPrimefactorOf[num];
                num /= minPrimefactorOf[num];
            }

            res[i][0] = first;
            res[i][1] = second;
        }

        for (int i = 0; i < 2; i++) {
            out.print(res[0][i]);
            for (int j = 1; j < n; j++) {
                out.print(" ");
                out.print(res[j][i]);
            }
            out.println();
        }

        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    public void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int[] minPrimefactorOf = new int[10000001];
        for (int i = 2; i <= 1000000; i++) {
            if (minPrimefactorOf[i] == 0) {
                minPrimefactorOf[i] = i;
                for (int j = 2 * i; j <= 1000000; j += i) {

                    minPrimefactorOf[j] = i;
                }
            }
        }

        int n = Integer.parseInt(f.readLine());
        int[][] res = new int[n][2];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(tokenizer.nextToken());
            int firstPrime = minPrimefactorOf[num];
            int first = 1;
            int second = 1;
            while (minPrimefactorOf[num] == firstPrime) {
                first *= firstPrime;
                num /= firstPrime;
            }

            if (num == 1) {
                res[i][0] = -1;
                res[i][1] = -1;
                continue;
            }

            while (num > 1) {
                second *= minPrimefactorOf[num];
                num /= minPrimefactorOf[num];
            }

            res[i][0] = first;
            res[i][1] = second;
        }

        for (int i = 0; i < 2; i++) {
            out.print(res[0][i]);
            for (int j = 1; j < n; j++) {
                out.print(" ");
                out.print(res[j][i]);
            }
            out.println();
        }

        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Task4 {

    public static void main(String[] args) throws IOException {
        new Task4().solve();
    }

    public void solve() throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int[] minPrimefactorOf = new int[100000001];
        for (int i = 2; i <= 10000000; i++) {
            if (minPrimefactorOf[i] == 0) {
                minPrimefactorOf[i] = i;
                for (int j = 2 * i; j <= 10000000; j += i) {
                    minPrimefactorOf[j] = i;
                }
            }
        }

        int n = Integer.parseInt(f.readLine());
        int[][] res = new int[n][2];
        StringTokenizer tokenizer = new StringTokenizer(f.readLine());
        for (int i = 0; i < n; i++) {
            int num = Integer.parseInt(tokenizer.nextToken());
            int firstPrime = minPrimefactorOf[num];
            int first = 1;
            int second = 1;
            while (minPrimefactorOf[num] == firstPrime) {
                first *= firstPrime;
                num /= firstPrime;
            }

            if (num == 1) {
                res[i][0] = -1;
                res[i][1] = -1;
                continue;
            }

            while (num > 1) {
                second *= minPrimefactorOf[num];
                num /= minPrimefactorOf[num];
            }

            res[i][0] = first;
            res[i][1] = second;
        }

        for (int i = 0; i < 2; i++) {
            out.print(res[0][i]);
            for (int j = 1; j < n; j++) {
                out.print(" ");
                out.print(res[j][i]);
            }
            out.println();
        }

        out.close();
    }
}


#include <bits/stdc++.h>

using namespace std;

int sum_digits(string n) {
	int temp = 0;
	for(int i = 0; i < n.length(); i++) {
		temp += (int)n[i] - (int)'0';
	}
	return temp;
}

int cnt_zero(string n) {
	int cnt = 0;
	for(int i = 0; i < n.length(); i++) {
		++cnt;
	}
	return cnt;
}

int main() {
	int k;
	string n;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> k;
	cin >> n;
	sort(n.begin(), n.end());
	int ans = 0;
	int sum_of_digits = sum_digits(n);
	if (sum_of_digits >= k) {
		printf("0\n");
	} else {
		int supposed_digits = (int)ceil(k/9.0);
		for(int i = 0; i < n.length() - supposed_digits; i++) {
			n = '0' + n;
		}
		int selisih = k - sum_digits(n);
		int cnt = 0;
		int i = 0;
		while(selisih > 0) {
			selisih -= 9 - ((int)n[i] - (int)'0');
			++cnt;
		}
		printf("%d\n", cnt);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int sum_digits(string n) {
	int temp = 0;
	for(int i = 0; i < n.length(); i++) {
		temp += (int)n[i] - (int)'0';
	}
	return temp;
}

int cnt_zero(string n) {
	int cnt = 0;
	for(int i = 0; i < n.length(); i++) {
		++cnt;
	}
	return cnt;
}

int main() {
	int k;
	string n;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> k;
	cin >> n;
	sort(n.begin(), n.end());
	int ans = 0;
	int sum_of_digits = sum_digits(n);
	if (sum_of_digits >= k) {
		printf("0\n");
	} else {
		int selisih = k - sum_of_digits;
		int cnt = 0;
		int i = 0;
		while(selisih > 0) {
			selisih -= 9 - ((int)n[i] - (int)'0');
			++cnt;
		}
		printf("%d\n", cnt);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int sum_digits(string n) {
	int temp = 0;
	for(int i = 0; i < n.length(); i++) {
		temp += (int)n[i] - (int)'0';
	}
	return temp;
}

int cnt_zero(string n) {
	int cnt = 0;
	for(int i = 0; i < n.length(); i++) {
		++cnt;
	}
	return cnt;
}

int main() {
	int k;
	string n;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> k;
	cin >> n;
	sort(n.begin(), n.end());
	int ans = 0;
	int sum_of_digits = sum_digits(n);
	if (sum_of_digits >= k) {
		printf("0\n");
	} else {
		// cout << sum_of_digits << endl;
		int selisih = k - sum_of_digits;
		int cnt = 0;
		int i = 0;
		while(selisih > 0) {
			selisih -= 9 - ((int)n[i] - (int)'0');
			++cnt;
			++i;
		}
		printf("%d\n", cnt);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,ppp,x,sum;
	while(~ scanf("%d",&n))
	{
		//ppp = 1;
		sum = 0;
		while(~ scanf("%1d",&x))
			sum += x;
		ppp = n - sum;
		sum = 0;
		while(ppp > 0){ppp /= 10;sum ++;}
		printf("%d\n",sum);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,ppp,x,sum;
	while(~ scanf("%d",&n))
	{
		//ppp = 1;
		sum = 0;
		while(~ scanf("%1d",&x))
			sum += x;
		ppp = n - (sum % n);
		if(ppp == n)ppp = 0;
		printf("%d\n",ppp);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int x[11];

int main()
{
	int n,i,sum,len,e,ans,tmp;
	while(~ scanf("%d",&n))
	{
		len = 1;
		sum = 0;
		ans = 0;
		memset(x,0,sizeof(x));
		while(~ scanf("%1d",&tmp))
			sum += tmp, x[tmp] ++;
		if(sum >= n)
		{
			printf("0\n");
			continue;
		}
		for(int i = 0;i <= 9;i ++)
			if(sum >= n)break;
			else
			{
				tmp = 0;
				while(sum < n)
				{
					sum += 9 - i;
					ans ++;
					tmp ++;
					if(tmp >= x[i])break;
				}
			}
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,ppp,x,sum;
	while(~ scanf("%d",&n))
	{
		//ppp = 1;
		sum = 0;
		while(~ scanf("%1d",&x))
			sum += x;
		ppp = (n - (sum % n)) % n;
		printf("%d\n",ppp ? ppp : n);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
	int n,ppp,x,sum;
	while(~ scanf("%d",&n))
	{
		//ppp = 1;
		sum = 0;
		while(~ scanf("%1d",&x))
			sum += x;
		ppp = n - sum;
		if(ppp <= 0)ppp = 0;
		printf("%d\n",ppp);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int x[100009];

bool cmp(const int &a,const int &b)
{
	return a > b;
}

int main()
{
	int n,i,sum,len,e,ans;
	while(~ scanf("%d",&n))
	{
		len = 1;
		sum = 0;
		ans = 0;
		while(~ scanf("%1d",&x[len]))
			sum += x[len], len ++;
		sort(x + 1,x + len + 1);
		if(sum >= n)
		{
			printf("0\n");
			continue;
		}
		for(int i = 1;i <= len;i ++)
			if(x[i] == 9)
				continue;
			else
			{
				ans ++;
				sum += 9 - x[i];
				if(sum > n)break;
			}
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int x[11];

int main()
{
	int n,i,sum,len,e,ans,tmp;
	while(~ scanf("%d",&n))
	{
		len = 1;
		sum = 0;
		ans = 0;
		memset(x,0,sizeof(x));
		while(~ scanf("%1d",&tmp))
			sum += tmp, x[tmp] ++;
		if(sum >= n)
		{
			printf("0\n");
			continue;
		}
		for(int i = 0;i <= 9;i ++)
			if(sum >= n)break;
			else
			{
				tmp = 0;
				while(sum <= n)
				{
					sum += 9 - i;
					ans ++;
					tmp ++;
					if(tmp >= x[i])break;
				}
			}
		printf("%d\n", ans);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int x[11];

int main()
{
	int n,i,sum,len,e,ans,tmp;
	while(~ scanf("%d",&n))
	{
		len = 1;
		sum = 0;
		ans = 0;
		memset(x,0,sizeof(x));
		while(~ scanf("%1d",&tmp))
			sum += tmp, x[tmp] ++;
		if(sum >= n)
		{
			printf("0\n");
			continue;
		}
		for(int i = 0;i <= 9;i ++)
			if(sum >= n)break;
			else
			{
				tmp = 0;
				while(sum < n && tmp < x[i])
				{
					sum += 9 - i;
					ans ++;
					tmp ++;
				}
			}
		printf("%d\n", ans);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;

char s[maxn];
int a[20];
int k,sum,len,num,res;

int main() {
	scanf("%d",&k);
	scanf("%s",s);
	len = strlen(s);
	for(int i=0;i<len;i++) {
		num=s[i]-'0';
		sum+=num;
		a[9-num]++;
	}
	if(sum>=k) printf("0\n");
	else {
		k-=sum;
		res=0;
		for(int i=9;i;i--) {
			if(k>i*a[i]) {
				k-=i*a[i];
				res+=a[i];
			}
			else {
				res+=k/i+(k%i?1:0);
				break;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;

char s[maxn];
int a[20];
int k,sum,len,num,res;

int main() {
	scanf("%d",&k);
	scanf("%s",s);
	len = strlen(s);
	for(int i=0;i<len;i++) {
		num=s[i]-'0';
		sum+=num;
		a[9-num]++;
	}
	if(sum>=k) printf("0\n");
	else {
		k-=sum;
		res=0;
		for(int i=9;i;i--) {
			if(k>i*a[i]) {
				k-=i*a[i];
				res+=a[i];
			}
			else {
				res+=k/i+1;
				break;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;

char s[maxn];
int k,sum,len;

int main() {
	scanf("%d",&k);
	scanf("%s",s);
	len = strlen(s);
	for(int i=0;i<len;i++) sum+=s[i]-'0';
	if(sum>=k) printf("0");
	else printf("%d\n",k-sum);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;

char s[maxn];
int a[20];
int k,sum,len,num,res;

int main() {
	scanf("%d",&k);
	scanf("%s",s);
	len = strlen(s);
	for(int i=0;i<len;i++) {
		num=s[i]-'0';
		sum+=num;
		a[9-num]++;
	}
	if(sum>=k) printf("0\n");
	else {
		k-=sum;
		res=0;
		for(int i=8;i;i--) {
			if(k>i*a[i]) {
				k-=i*a[i];
				res+=i;
			}
			else {
				res+=k/i+1;
				break;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;

char s[maxn];
int a[20];
int k,sum,len,num,res;

int main() {
	scanf("%d",&k);
	scanf("%s",s);
	len = strlen(s);
	for(int i=0;i<len;i++) {
		num=s[i]-'0';
		sum+=num;
		a[9-num]++;
	}
	if(sum>=k) printf("0\n");
	else {
		k-=sum;
		res=0;
		for(int i=9;i;i--) {
			if(k>=i*a[i]) {
				k-=i*a[i];
				res+=a[i];
				if(k==0) break;
			}
			else {
				res+=k/i+1;
				break;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100000 + 10;

char s[maxn];
int a[20];
int k,sum,len,num,res;

int main() {
	scanf("%d",&k);
	scanf("%s",s);
	len = strlen(s);
	for(int i=0;i<len;i++) {
		num=s[i]-'0';
		sum+=num;
		a[9-num]++;
	}
	if(sum>=k) printf("0\n");
	else {
		k-=sum;
		res=0;
		for(int i=8;i;i--) {
			if(k>i*a[i]) {
				k-=i*a[i];
				res+=a[i];
			}
			else {
				res+=k/i+1;
				break;
			}
		}
		printf("%d\n",res);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,sum=0;
    string s;
    cin >> k >> s;
    int len = s.length(),cnt=0;
    for(int i=0;i<len;i++)
    {
        sum += s[i]-'0';
    }
    if(sum>=k)
    {
        cout << 0 << endl;
        return 0;
    }
    cnt = 0;
    for(int i=0;i<len;i++)
    {
        int temp = '9'-s[i];
        if(sum+temp>=k)
        {
            cnt++;
            break;
        }
        else if(temp>0)
            sum += temp,cnt++;
    }
    cout << cnt << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,sum=0;
    string s;
    cin >> k >> s;
    int len = s.length(),cnt=0;
    for(int i=0;i<len;i++)
    {
        sum += s[i]-'0';
    }
    if(sum>=k)
    {
        cout << 0 << endl;
        return 0;
    }
    cnt = 0;
    for(int i=0;i<len;i++)
    {
        int temp = '9'-s[i];
        if(sum+temp>=k)
        {
            cnt++;
            break;
        }
        else
            sum += temp,cnt++;
    }
    cout << cnt << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,sum=0;
    string s;
    cin >> k >> s;
    int len = s.length();
    for(int i=0;i<len;i++)
    {
        sum += s[i]-'0';
    }
    if(sum>=k)
        cout << 0 << endl;
    else
        cout << k-sum << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,sum=0;
    string s;
    cin >> k >> s;
    int len = s.length(),cnt=0;
    for(int i=0;i<len;i++)
    {
        sum += s[i]-'0';
    }
    if(sum>=k)
    {
        cout << 0 << endl;
        return 0;
    }
    cnt = 0;
    sort(s.begin(),s.end());
    for(int i=0;i<len;i++)
    {
        int temp = '9'-s[i];
        if(sum+temp>=k)
        {
            cnt++;
            break;
        }
        else if(temp>0)
            sum += temp,cnt++;
    }
    cout << cnt << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,sum=0;
    string s;
    cin >> k >> s;
    int len = s.length();
    for(int i=0;i<len;i++)
    {
        sum += s[i]-'0';
    }
    if(sum>=k)
        cout << 0 << endl;
    else
        cout << 1 << endl;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int k;
	char c;
	int count[10], sum = 0, ans = 0;
	cin >> k;
	c = getchar();	// for enter
	c = getchar();
	memset(count, 0, sizeof(int)*10);
	while (c >= '0' && c <= '9')
	{
		int digit = c - '0';
		sum += digit;
		count[digit]++;
		c = getchar();
	}
	// for (int i = 0; i < 10; ++i)
	// {
	// 	cout << i << " " << count[i] << endl;
	// }
	if(sum > k)
	{
		cout << ans << endl;
		return (0);
	}
	// cout << sum << endl;
	for (int i = 0; i < 9; ++i)
	{
		if ( sum + count[i] * (9 - i) < k )
		{
			sum += count[i]*(9-i);
			ans = ans + count[i];
		}
		else if ( sum + count[i] * (9 - i) > k )
		{
			if (sum + (9-i)*int((k - sum)*1.0/(9 - i)) > k)
				ans = ans + int((k - sum)*1.0/(9 - i));
			else
				ans = ans + int((k - sum)*1.0/(9 - i)) + 1;
			break;
		}
	}
	cout << ans << endl;
	return (0);

}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int k;
	char c;
	int count[10], sum = 0, ans = 0;
	cin >> k;
	c = getchar();	// for enter
	c = getchar();
	memset(count, 0, sizeof(int)*10);
	while (c >= '0' && c <= '9')
	{
		int digit = c - '0';
		sum += digit;
		count[digit]++;
		c = getchar();
	}
	if(sum > k)
	{
		cout << ans << endl;
		return (0);
	}
	for (int i = 0; i < 9; ++i)
	{
		if ( sum + count[i] * (9 - i) < k )
		{
			sum += count[i]*(9-i);
			ans = ans + count[i];
		}
		else if ( sum + count[i] * (9 - i) > k )
		{
			if (sum + (9-i)*int((k - sum)*1.0/(9 - i)) > k)
				ans = ans + int((k - sum)*1.0/(9 - i));
			else
				ans = ans + int((k - sum)*1.0/(9 - i)) + 1;
		}
	}
	cout << ans << endl;
	return (0);

}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int k;
	char c;
	int count[10], sum = 0, ans = 0;
	cin >> k;
	c = getchar();	// for enter
	c = getchar();
	memset(count, 0, sizeof(int)*10);
	while (c >= '0' && c <= '9')
	{
		int digit = c - '0';
		sum += digit;
		count[digit]++;
		c = getchar();
	}
	// for (int i = 0; i < 10; ++i)
	// {
	// 	cout << i << " " << count[i] << endl;
	// }
	if(sum > k)
	{
		cout << ans << endl;
		return (0);
	}
	// cout << sum << endl;
	for (int i = 0; i < 9; ++i)
	{
		if ( sum + count[i] * (9 - i) < k )
		{
			sum += count[i]*(9-i);
			ans = ans + count[i];
		}
		else if ( sum + count[i] * (9 - i) > k )
		{
			if (sum + (9-i)*int((k - sum)*1.0/(9 - i)) >= k)
				ans = ans + int((k - sum)*1.0/(9 - i));
			else
				ans = ans + int((k - sum)*1.0/(9 - i)) + 1;
			break;
		}
	}
	cout << ans << endl;
	return (0);

}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int k;
	char c;
	int count[10], sum = 0, ans = 0;
	cin >> k;
	c = getchar();	// for enter character
	c = getchar();
	memset(count, 0, sizeof(int)*10);
	while (c >= '0' && c <= '9')
	{
		int digit = c - '0';
		sum += digit;
		count[digit]++;
		c = getchar();
	}
	if(sum > k)
	{
		cout << ans << endl;
		return (0);
	}
	for (int i = 0; i < 9; ++i)
	{
		if ( sum + count[i] * (9 - i) < k )
		{
			sum += count[i]*(9-i);
			ans = ans + count[i];
		}
		else if ( sum + count[i] * (9 - i) >= k )
		{
			if (sum + (9-i)*int((k - sum)*1.0/(9 - i)) >= k)
			{
				sum = sum + (9-i)*int((k - sum)*1.0/(9 - i));
				ans = ans + int((k - sum)*1.0/(9 - i));
			}
			else
			{
				sum = sum + (9-i)*(int((k - sum)*1.0/(9 - i)) + 1);
				ans = ans + int((k - sum)*1.0/(9 - i)) + 1;
			}
			break;
		}
	}
	cout << ans << endl;
	return (0);

}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int k;
	char c;
	int count[10], sum = 0, ans = 0;
	cin >> k;
	c = getchar();	// for enter character
	c = getchar();
	memset(count, 0, sizeof(int)*10);
	while (c >= '0' && c <= '9')
	{
		int digit = c - '0';
		sum += digit;
		count[digit]++;
		c = getchar();
	}
	if(sum >= k)
	{
		cout << ans << endl;
		return (0);
	}
	for (int i = 0; i < 9; ++i)
	{
		if ( sum + count[i] * (9 - i) < k )
		{
			sum += count[i]*(9-i);
			ans = ans + count[i];
		}
		else if ( sum + count[i] * (9 - i) > k )
		{
			if (sum + (9-i)*int((k - sum)*1.0/(9 - i)) >= k)
			{
				sum = sum + (9-i)*int((k - sum)*1.0/(9 - i));
				ans = ans + int((k - sum)*1.0/(9 - i));
			}
			else
			{
				sum = sum + (9-i)*(int((k - sum)*1.0/(9 - i)) + 1);
				ans = ans + int((k - sum)*1.0/(9 - i)) + 1;
			}
			break;
		}
	}
	cout << ans << endl;
	return (0);

}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;

int main()
{
	int k;
	char c;
	int count[10], sum = 0, ans = 0;
	cin >> k;
	c = getchar();	// for enter
	c = getchar();
	memset(count, 0, sizeof(int)*10);
	while (c >= '0' && c <= '9')
	{
		int digit = c - '0';
		sum += digit;
		count[digit]++;
		c = getchar();
	}
	for (int i = 0; i < 10; ++i)
	{
		// cout << i << " " << count[i] << endl;
	}
	if(sum >= k)
	{
		cout << ans << endl;
		return (0);
	}
	for (int i = 0; i < 9; ++i)
	{
		// cout << sum << endl;
		if ( sum + count[i] * (9 - i) < k )
		{
			sum += count[i]*(9-i);
			ans = ans + count[i];
		}
		else if ( sum + count[i] * (9 - i) >= k )
		{
			int v = int((k - sum)*1.0/(9 - i));
			// cout << v << " v" << endl;
			if (sum + (9-i)*v >= k)
			{
				sum = sum + (9-i)*v;
				ans = ans + v;
			}
			else
			{
				sum = sum + (9-i)*(v + 1);
				ans = ans + v + 1;
			}
			break;
		}
	}
	cout << ans << endl;
	return (0);

}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define maxn 110000
#define ins 0x3f3f3f3f
typedef long long ll;
char s[maxn];
int main(){
    int k ;
    scanf("%d%s",&k,s);
    int sum=0;
    for(int i = 0 ; s[i] ; i++){
        sum+=s[i]-'0';
    }
    if(sum>=k){
        printf("0");
    }else if(sum<k){
        int n = k-sum;
        int i = 0;
        //printf("%d\n",n);
        int ans=strlen(s);
        while(n>0){
            n=n-('9'-s[i]);
            i++;
            //printf("%d",n);
            ans--;
        }
        printf("%d",ans);
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define maxn 110000
#define ins 0x3f3f3f3f
typedef long long ll;
char s[maxn];
int a[maxn];
int main(){
    int k ;
    scanf("%d%s",&k,s);
    int sum=0;
    for(int i = 0 ; s[i] ; i++){
        sum+=s[i]-'0';
        a[i]=s[i]-'0';
    }
    if(sum>=k){
        printf("0");
    }else if(sum<k){
        int n = k-sum;
        int i = 0;
        //printf("%d\n",n);
        sort(a,a+strlen(s[i]));
        int ans=0;
        while(n>0){
            n=n-(9-a[i]);
            i++;
            //printf("%d",n);
            ans++;
        }
        printf("%d",ans);
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define maxn 110000
#define ins 0x3f3f3f3f
typedef long long ll;
char s[maxn];
int main(){
    int k ;
    scanf("%d%s",&k,s);
    int sum=0;
    for(int i = 0 ; s[i] ; i++){
        sum+=s[i]-'0';
    }
    if(sum>=k){
        printf("0");
    }else if(sum<k){
        int n = k-sum;
        int i = 0;
        int ans=strlen(s);
        while(n&&s[i]){
            n-=(s[i]-'0');
            i++;
            ans--;
        }
        printf("%d",ans);
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define maxn 110000
#define ins 0x3f3f3f3f
typedef long long ll;
char s[maxn];
int a[maxn];
int main(){
    int k ;
    scanf("%d%s",&k,s);
    int sum=0;
    for(int i = 0 ; s[i] ; i++){
        sum+=s[i]-'0';
        a[i]=s[i]-'0';
    }
    if(sum>=k){
        printf("0");
    }else if(sum<k){
        int n = k-sum;
        int i = 0;
        //printf("%d\n",n);
        sort(a,a+strlen(s));
        int ans=0;
        while(n>0){
            n=n-(9-a[i]);
            i++;
            //printf("%d",n);
            ans++;
        }
        printf("%d",ans);
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
#define maxn 110000
#define ins 0x3f3f3f3f
typedef long long ll;
char s[maxn];
int main(){
    int k ;
    scanf("%d%s",&k,s);
    int sum=0;
    for(int i = 0 ; s[i] ; i++){
        sum+=s[i]-'0';
    }
    if(sum>=k){
        printf("0");
    }else if(sum<k){
        int n = k-sum;
        int i = 0;
        //printf("%d\n",n);
        int ans=0;
        while(n>0){
            n=n-('9'-s[i]);
            i++;
            //printf("%d",n);
            ans++;
        }
        printf("%d",ans);
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long a[100005];
bool cmp(long long a,long long b){
	return a<b;
}
int main()
{
	long long n,k;
	char temp;
	long long cnt=0;
	long long tot=0;
	cin>>k;
		temp=getchar();
		temp=getchar();
		 while(temp>='0'&&temp<='9')
		{
			cnt++;
		    a[cnt]=temp-'0';
		    tot+=a[cnt];
		temp=getchar();
		}
	sort(a+1,a+1+cnt,cmp);
	if(tot>=k) {cout<<"0";return 0;}
	for(long long i=1;i<=cnt;i++)if(tot+=9-a[i]>=k){
		cout<<i;
		return 0;
	}
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
long long a[11];
int main()
{
	long long n,k;
	long long cnt=0,tot=k;
	long long sum=0;
	char temp;
	cin>>k;
    temp=getchar();
    temp=getchar();
     while(temp>='0'&&temp<='9')
    {
	   sum=temp-'0';
	   a[sum]++;
	temp=getchar();
    }
    for(long long i=1;i<=9;i++){
	tot+=a[i]*i;}
	if(tot>=k) {cout<<"0";}
	else
	{
		for(long long i=0;i<=9;i++)
		{
			for(long long j=1;j<=a[i];j++)
			{
				cnt++;
				tot+=9-a[i];
				if(tot>=k){cout<<cnt;return 0;
				}
			}
		}
	}
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long a[100005];
bool cmp(long long a,long long b){
	return a<b;
}
int main()
{
	long long n,k;
	char temp;
	long long cnt=0;
	long long tot=0;
	cin>>k;
		temp=getchar();
		temp=getchar();
		 while(temp>='0'&&temp<='9')
		{
			cnt++;
		    a[cnt]=temp-'0';
		    tot+=a[cnt];
		temp=getchar();
		}
	sort(a+1,a+1+cnt,cmp);
	if(tot>=k) {cout<<"0";return 0;}
	for(long long i=1;i<=cnt;i++){
		tot+=9-a[i];
		if(tot>=k)
		{
		cout<<i;
		return 0;
		}
	}
}


#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100005];
bool cmp(int a,int b){
	return a<b;
}
int main()
{
	int n,k;
	char temp;
	int cnt=0;
	int tot=0;
	cin>>k;
		temp=getchar();
		temp=getchar();
		 while(temp>='0'&&temp<='9')
		{
			cnt++;
		    a[cnt]=temp-'0';
		    tot+=a[cnt];
		temp=getchar();
		}
	sort(a+1,a+1+cnt,cmp);
	if(tot>=k) {cout<<"0";return 0;}
	for(int i=1;i<=cnt;i++)if(tot+=9-a[i]>=k){
		cout<<i;
		return 0;
	}
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define int long long
main()
{
	int n,k;
	int cnt=0,tot=0;
	int sum=0;
	char temp;
	cin>>k;
    temp=getchar();
    temp=getchar();
     while(temp>='0'&&temp<='9')
    {
	   k-=temp-'0';
	   if(k<=0){
		break;
	}
	cnt++;
	temp=getchar();
    }
    if(k<=0) cout<<0;
     else cout<<k;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    long long k;
    char n[100005];
    char ans[100005];
    cin>>k>>n;
    long long sumnow=0;
    for(int i=0;i<strlen(n);i++)
    {
        sumnow+=(n[i]-'0');
    }
    if(sumnow>=k)
        cout<<"0"<<endl;
    else
    {
        long long diff=k-sumnow;
        int t=0;
        for(int i=strlen(n)-1;i>=0;i--)
        {
            if(diff+(n[i]-'0')>9)
            {
                ans[t++]=(9-(n[i]-'0'))+'0';
                diff=diff-(9-(n[i]-'0'));
            }
            else if(diff+(n[i]-'0')<=9)
            {
                ans[t++]=diff+'0';
                diff=0;
                break;
            }
        }
        for(int i=t-1;i>=0;i--)
        {
            cout<<ans[i];
        }
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main()
{
    long long k;
    char n[100005];
    char ans[100005];
    cin>>k>>n;
    long long sumnow=0;
    for(int i=0;i<strlen(n);i++)
    {
        sumnow+=(n[i]-'0');
    }
    if(sumnow>=k)
        cout<<"0"<<endl;
    else
    {
        long long sum=0;
        sort(n,n+strlen(n));
        for(int i=0;i<strlen(n);i++)
        {
            sum=sum+(9-(n[i]-'0'));
            if(sumnow+sum>k)
            {
                cout<<i+1<<endl;
                break;
            }
        }
    }
    return 0;
}


#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;

int main()
{
    long long k;
    char n[100005];
    char ans[100005];
    cin>>k>>n;
    long long sumnow=0;
    for(int i=0;i<strlen(n);i++)
    {
        sumnow+=(n[i]-'0');
    }
    if(sumnow>=k)
        cout<<"0"<<endl;
    else
    {
        long long sum=0;
        sort(n,n+strlen(n));
        for(int i=0;i<strlen(n);i++)
        {
            sum=sum+(9-(n[i]-'0'));
            if(sumnow+sum>=k)
            {
                cout<<i+1<<endl;
                break;
            }
        }
    }
    return 0;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    long long k;
    char n[100005];
    char ans[100005];
    cin>>k>>n;
    long long sumnow=0;
    for(int i=0;i<strlen(n);i++)
    {
        sumnow+=(n[i]-'0');
    }
    if(sumnow>=k)
        cout<<"0"<<endl;
    else
    {
        long long diff=k-sumnow;
        int t=0;
        for(int i=strlen(n)-1;i>=0;i--)
        {
            if(diff+(n[i]-'0')>9)
            {
                ans[t++]=(9-(n[i]-'0'))+'0';
                diff=diff-(9-(n[i]-'0'));
                if(diff==0)
                    break;
            }
            else if(diff+(n[i]-'0')<=9)
            {
                ans[t++]=diff+'0';
                diff=0;
                break;
            }
        }
        for(int i=t-1;i>=0;i--)
        {
            cout<<ans[i];
        }
        cout<<endl;
    }
    return 0;
}


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    long long k;
    char n[100005];
    char ans[100005];
    cin>>k>>n;
    long long sumnow=0;
    for(int i=0;i<strlen(n);i++)
    {
        sumnow+=(n[i]-'0');
    }
    //cout<<sumnow<<endl;
    if(sumnow>=k)
        cout<<"0"<<endl;
    else
    {
        long long diff=k-sumnow;
        int t=0;
        for(int i=strlen(n)-1;i>=0;i--)
        {
            if(diff+(n[i]-'0')>9)
            {
                ans[t++]=(9-(n[i]-'0'))+'0';
                diff=diff-(9-(n[i]-'0'));
                if(diff==0)
                    break;
            }
            else
            {
                ans[t++]=diff+'0';
                diff=0;
                break;
            }
        }
        cout<<t<<endl;
        cout<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
void sieve(){pr[0]=1;pr[1]=1;for(int i=2;i<sqrt(1000007);i++){for(int j=2*i;j<=1000007;j+=i){pr[j]=1;}}}
ll fashtpower(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ull lopow(ll x,ll y){ull res=1ULL;while(y){if(y&1)res*=(ull)x;y>>=1;x*=x;}return res;}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		ld n;
		string s;
		cin>>n;
		cin>>s;
		ld sum=0;
		int i=0;
		while(s[i]){
			sum+=(ld)(s[i]-48);
			i++;
		}
		//cout<<sum;
		if(sum<n){
			if(ceil(n-sum)/9==floor((n-sum)/9)){
					cout<<ceil((n-sum)/9)+1;
			}else{
					cout<<ceil((n-sum)/9);
			}
		}

		else{
			cout<<0;
		}

}


#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
void sieve(){pr[0]=1;pr[1]=1;for(int i=2;i<sqrt(1000007);i++){for(int j=2*i;j<=1000007;j+=i){pr[j]=1;}}}
ll fashtpower(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ull lopow(ll x,ll y){ull res=1ULL;while(y){if(y&1)res*=(ull)x;y>>=1;x*=x;}return res;}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int n;
		char s[100003];
		cin>>n;
		cin>>s;
		int sum=0;
		int i=0;
		sort(s,s+strlen(s));
		while(s[i]){
			sum+=(s[i]-48);
			i++;

		}i=0;
		int ans=0;
		while(sum<n){
			sum+=9-(s[i]-48);
			ans++;
			i++;
		}
		cout<<ans;

}


#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
void sieve(){pr[0]=1;pr[1]=1;for(int i=2;i<sqrt(1000007);i++){for(int j=2*i;j<=1000007;j+=i){pr[j]=1;}}}
ll fashtpower(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ull lopow(ll x,ll y){ull res=1ULL;while(y){if(y&1)res*=(ull)x;y>>=1;x*=x;}return res;}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		ld n;
		string s;
		cin>>n;
		cin>>s;
		ld sum=0;
		int i=0;
		while(s[i]){
			sum+=(s[i])-48;
			i++;
		}
		//cout<<sum;
		if(sum<n)
		cout<<ceil((n-sum)/9);
		else{
			cout<<0;
		}

}


#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
void sieve(){pr[0]=1;pr[1]=1;for(int i=2;i<sqrt(1000007);i++){for(int j=2*i;j<=1000007;j+=i){pr[j]=1;}}}
ll fashtpower(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ull lopow(ll x,ll y){ull res=1ULL;while(y){if(y&1)res*=(ull)x;y>>=1;x*=x;}return res;}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		double n;
		string s;
		cin>>n;
		cin>>s;
		double sum=0;
		int i=0;
		while(s[i]){
			sum+=(s[i]-48);
			i++;
		}
		//cout<<sum;
		if(sum<n){
			if(ceil(n-sum)/9==floor((n-sum)/9)){
					cout<<ceil((n-sum)/9)+1;
			}else{
					cout<<ceil((n-sum)/9);
			}
		}

		else{
			cout<<0;
		}

}