import java.util.*;
import java.io.*;
public class D89
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int [] a = new int [n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int [] p = new int[(int) 1e7 + 1]; int [] q = new int[(int) 1e7 + 1];
        for (int i = 2; i <= Math.sqrt(1e7 + 2); i++) {
            if (p[i] > 0) continue;
            for (int j = i; j <= p.length - 1; j += i) {
                if (q[j] > 0) continue;
                else if (p[j] > 0 && q[j] == 0) q[j] = i;
                else if (p[j] == 0) p[j] = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(p[a[i]] + " ");
            }
        }
        out.println();
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(a[i] / p[a[i]] + " ");
            }
        }
        out.println();
        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}


import java.util.*;
import java.io.*;
public class D89
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int [] a = new int [n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int [] p = new int[(int) 1e7 + 1];
        for (int i = 2; i <= Math.sqrt(1e7 + 2); i++) {
            if (p[i] > 0) continue;
            for (int j = i; j <= p.length - 1; j += i) {
                if (p[j] > 0) continue;
                else p[j] = i;
            }
        }
        int [] one = new int [n];
        for (int i = 0; i < n; i++) one[i] = p[a[i]];
        int [] two = new int [n];
        for (int i = 0; i < n; i++) {
            int res = a[i]; int stor = p[a[i]];
            while (stor != 0 && res % stor == 0) res /= stor;
            if (res == 1 || stor == 0) two[i] = -1; else two[i] = res;
        }
        for (int i = 0; i < n; i++) {
            if (two[i] == -1) one[i] = -1;
        }
        for (int i = 0; i < n; i++) {
            out.print(one[i] + " ");
        }
        out.println();
        for (int i = 0; i < n; i++) {
            out.print(two[i] + " ");
        }

        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}


import java.util.*;
import java.io.*;
public class D89
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int [] a = new int [n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int [] p = new int[(int) 1e7 + 1]; int [] q = new int[(int) 1e7 + 1];
        for (int i = 2; i <= Math.sqrt(1e7 + 2); i++) {
            if (p[i] > 0) continue;
            for (int j = i; j <= p.length - 1; j += i) {
                if (q[j] > 0) continue;
                else if (p[j] > 0 && q[j] == 0) q[j] = i;
                else if (p[j] == 0) p[j] = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(p[a[i]] + " ");
            }
        }
        out.println();
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(q[a[i]] + " ");
            }
        }
        out.println();
        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}


import java.util.*;
import java.io.*;
public class D89
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int [] a = new int [n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int [] p = new int[(int) 1e7 + 1];
        for (int i = 2; i <= Math.sqrt(1e7 + 2); i++) {
            if (p[i] > 0) continue;
            for (int j = i; j <= p.length - 1; j += i) {
                if (p[j] > 0) continue;
                else p[j] = i;
            }
        }
        int [] one = new int [n];
        for (int i = 0; i < n; i++) one[i] = p[a[i]];
        int [] two = new int [n];
        for (int i = 0; i < n; i++) {
            int res = a[i]; int stor = p[a[i]];
            while (res % stor == 0) res /= stor;
            if (res == 1) two[i] = -1; else two[i] = res;
        }
        for (int i = 0; i < n; i++) {
            if (two[i] == -1) one[i] = -1;
        }
        for (int i = 0; i < n; i++) {
            out.print(one[i] + " ");
        }
        out.println();
        for (int i = 0; i < n; i++) {
            out.print(two[i] + " ");
        }

        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}


import java.util.*;
import java.io.*;
public class D89
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int [] a = new int [n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int [] p = new int[(int) 1e7 + 1]; int [] q = new int[(int) 1e7 + 1];
        for (int i = 2; i <= Math.sqrt(1e7 + 2); i++) {
            if (p[i] > 0) continue;
            for (int j = i; j <= p.length - 1; j += i) {
                if (q[j] > 0) continue;
                else if (p[j] > 0 && q[j] == 0) q[j] = i;
                else if (p[j] == 0) p[j] = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(p[a[i]] + " ");
            }
        }
        out.println();
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                int res = a[i]; int stor = p[a[i]];
                while (res % stor == 0) res /= stor;
                out.print(res + " ");
            }
        }
        out.println();
        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}


import java.util.*;
import java.io.*;
public class D89
{
    public static void main(String [] args)
    {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int [] a = new int [n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int [] p = new int[(int) 1e7 + 1]; int [] q = new int[(int) 1e7 + 1];
        for (int i = 2; i <= Math.sqrt(1e7 + 2); i++) {
            if (p[i] > 0) continue;
            for (int j = i; j <= p.length - 1; j += i) {
                if (q[j] > 0) continue;
                else if (p[j] > 0 && q[j] == 0 && j % (p[j] + i) != 0) q[j] = i;
                else if (p[j] == 0) p[j] = i;
            }
        }
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(p[a[i]] + " ");
            }
        }
        out.println();
        for (int i = 0; i < n; i++) {
            if (p[a[i]] == 0 || q[a[i]] == 0) {
                out.print(-1 + " ");
            } else {
                out.print(q[a[i]] + " ");
            }
        }
        out.println();
        out.close();
    }

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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;
        }

    }

}


import java.io.*;
import java.util.*;
/**
  * Built using my Brain
  * Actual solution is at the bottom
  *
  * @author Lenard Hoffstader
*/

public class cfjava
{
  public static void main(String[] args)
  {
    OutputStream outputStream = System.out;
    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(outputStream);
    PROBLEM solver = new PROBLEM();
    int t=1;
    // t = in.nextInt();
    for(int i=0;i<t;i++){
      solver.solve(in, out);
    }
    out.close();
  }

  static class PROBLEM
  {
    public void solve(FastReader in,PrintWriter out)
    {
      int uv = 10000007;
      long pf[] = new long[uv+1];
      pf[1]=1;
      for(int i=2;i*i<=uv;i++){
        if(pf[i]==0){
          for(int j=i*i;j<=uv;j+=i){
            if(pf[j]==0)pf[j]=i;
          }
          pf[i]=i;
        }
      }
      for(int i=1;i<=uv;i++){
        if(pf[i]==0)pf[i]=i;
      }
      int n = in.nextInt();
      long x=0,y=0;
      long ans[][] = new long[2][n];
      for(int i=0;i<n;i++){
        x = in.nextLong();
        y = pf[(int)x];
        while(x%y==0){x/=y;}
        if(x==1){ans[0][i]=ans[1][i]=-1;}
        else {ans[0][i]=x;ans[1][i]=y;}
      }
      for(int i=0;i<n;i++){out.print(ans[0][i]+" ");}
      out.println();
      for(int i=0;i<n;i++){out.print(ans[1][i]+" ");}
    }
  }
  static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>>
  {
    public U x;
    public V y;

    public pair(U x, V y) {
      this.x = x;
      this.y = y;
    }

    public int compareTo(pair<U, V> other) {
      int i = x.compareTo(other.x);
      if (i != 0) return i;
      return y.compareTo(other.y);
    }

    public String toString() {
      return x.toString() + " " + y.toString();
    }

    public boolean equals(Object obj){
      if (this.getClass() != obj.getClass()) return false;
      pair<U, V> other = (pair<U, V>) obj;
      return x.equals(other.x) && y.equals(other.y);
    }
    public int hashCode(){
      return 31 * x.hashCode() + y.hashCode();
    }
  }
  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());}

    boolean nextBoolean(){return !(nextInt()==0);}
    // boolean nextBoolean(){return Boolean.parseBoolean(next());}

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


import java.io.*;
import java.util.*;
/**
  * Built using my Brain
  * Actual solution is at the bottom
  *
  * @author Lenard Hoffstader
*/

public class cfjava
{
  public static void main(String[] args)
  {
    OutputStream outputStream = System.out;
    FastReader in = new FastReader();
    PrintWriter out = new PrintWriter(outputStream);
    PROBLEM solver = new PROBLEM();
    int t=1;
    // t = in.nextInt();
    for(int i=0;i<t;i++){
      solver.solve(in, out);
    }
    out.close();
  }

  static class PROBLEM
  {
    public void solve(FastReader in,PrintWriter out)
    {
      int uv = 10000007;
      long pf[] = new long[uv+1];
      pf[1]=1;
      for(int i=2;i*i<=uv;i++){
        if(pf[i]==0){
          for(int j=i*i;j<=uv;j+=i){
            if(pf[j]==0)pf[j]=i;
          }
          pf[i]=i;
        }
      }
      int n = in.nextInt();
      long x=0,y=0;
      long ans[][] = new long[2][n];
      for(int i=0;i<n;i++){
        x = in.nextLong();
        y = pf[(int)x];
        while(x%y==0){x/=y;}
        if(x==1){ans[0][i]=ans[1][i]=-1;}
        else {ans[0][i]=x;ans[1][i]=y;}
      }
      for(int i=0;i<n;i++){out.print(ans[0][i]+" ");}
      out.println();
      for(int i=0;i<n;i++){out.print(ans[1][i]+" ");}
    }
  }
  static class pair<U extends Comparable<U>, V extends Comparable<V>> implements Comparable<pair<U, V>>
  {
    public U x;
    public V y;

    public pair(U x, V y) {
      this.x = x;
      this.y = y;
    }

    public int compareTo(pair<U, V> other) {
      int i = x.compareTo(other.x);
      if (i != 0) return i;
      return y.compareTo(other.y);
    }

    public String toString() {
      return x.toString() + " " + y.toString();
    }

    public boolean equals(Object obj){
      if (this.getClass() != obj.getClass()) return false;
      pair<U, V> other = (pair<U, V>) obj;
      return x.equals(other.x) && y.equals(other.y);
    }
    public int hashCode(){
      return 31 * x.hashCode() + y.hashCode();
    }
  }
  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());}

    boolean nextBoolean(){return !(nextInt()==0);}
    // boolean nextBoolean(){return Boolean.parseBoolean(next());}

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  FaastScanner scan=new FaastScanner(input);
	  int n=scan.nextInt();
	  int[] arrInput=new int[n];
	  int [] d1=new int[n];
	  int [] d2=new int[n];
	  int d_offset=0;
	  for(int index=0;index<n;index++)
	  {
		  arrInput[index]=scan.nextInt();
		  int[] arr=new int[arrInput[index]];
		  Arrays.fill(arr, 1);
		  int[] primeFact=new int[2];
	      int off=0;
	      int i=2;
	      for(;i<=(arrInput[index])/2;i++)
	       {
		      if(arr[i]==1)
		       {

		    	if(arrInput[index]%i==0)
			      {

		    		primeFact[off++]=i;
				    int temp1=arrInput[index];
		    		 while(temp1%i==0)
					  {
						temp1/=i;
					  }
					if(off==2)
					{
						break;
					}
			      }
		       }

		     for(int j=i*i;j<arrInput[index];j+=i)
		      {
			   arr[j]=0;
		      }

	       }
	    arr[0]=0;
	    arr[1]=0;
	    if(off>=2)
	     {
	    	//System.out.println(primeFact[0]+"\n" +primeFact[1]);
	    	d1[d_offset]=primeFact[0];
	    	d2[d_offset]=primeFact[1];
	    	d_offset++;
	     }
	    else
	     {
		    //System.out.println("-1" +"\n"+"-1");
	    	d1[d_offset]=-1;
	    	d2[d_offset]=-1;
	    	d_offset++;
	     }

	  }
	  print(d1);
	  print(d2);
	}
	static void print(int[] d)
	{
		for(int off=0;off<d.length;off++)
		{
		  System.out.print(d[off]+" ");
		}
		System.out.println();
	}

}
 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	static int []primeArr=new int[10000007];
	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  Writer out=new Writer();
	  FaastScanner scan=new FaastScanner(input);
	  factorization();
	  //print();
	  int n=scan.nextInt();

	  int [] l1=new int[n];
	  int [] l2=new int[n];

	  Arrays.fill(l1, -1);
	  Arrays.fill(l2, -1);
	  for(int i=0;i<n;i++)
	  {
	    int inputValue=scan.nextInt();
	    int d1=primeArr[inputValue];
	    int d2=inputValue;
	    while(d2%d1==0)
	     {
	     	d2/=d1;
	     }
	    if(d2>1)
	    {
	    	l1[i]=d1;
	    	l2[i]=d2;
	    }
	  }
	  for(int i=0;i<n;i++)
	  {
	   out.print(l1[i]+" ");
	  }
	  out.println();
	  for(int i=0;i<n;i++)
	  {
		  out.print(l2[i]+" ");
	  }
	  out.exit();
	 }

	static void sieve()
	 {
		/*for(long i=3;i<10000007;i+=2)
		{
			primeArr[(int)i]=1;
		}
      for(long i=3;i<10000007;i+=2)
      {
			if(primeArr[(int)i]==1)
			{
			 for(long j=i*i;j<10000007;j+=i)
			   {
				primeArr[(int)j]=0;
			   }
			}
      }
		primeArr[2]=1;
		primeArr[1]=primeArr[0]=0;*/
	 }
	static void factorization()
	{
		for(int i = 2; i<10000001; i++) {
			if(primeArr[i]!=0) continue;
			for(int j = 0; j<10000001; j+=i) if(primeArr[j]==0) primeArr[j] = i;
		}

	}
	static void print()
	{
		System.out.println(primeArr.length);
		for(int off=0;off<100;off++)
		{

				System.out.print(primeArr[off]+" ");

		}

	}

}

 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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

  class Writer {
		private PrintWriter pw;
		public Writer(){
			pw = new PrintWriter(System.out);
		}

		public Writer(String f){
			try {
				pw = new PrintWriter(new FileWriter(f));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		public void printArray(int[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
		}
		public void printlnArray(int[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
			pw.println();
		}
		public void printArray(long[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
		}
		public void printlnArray(long[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
			pw.println();
		}
		public void print(Object o) {
			pw.print(o.toString());
		}
		public void println(Object o) {
			pw.println(o.toString());
		}
		public void println() {
			pw.println();
		}
		public void flush() {
			pw.flush();
		}
		public void exit() {
			pw.close();
		}
	}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  FaastScanner scan=new FaastScanner(input);
	  int n=scan.nextInt();
	  int[] arrInput=new int[n];
	  int [] d1=new int[n];
	  int [] d2=new int[n];
	  int d_offset=0;
	  for(int index=0;index<n;index++)
	  {
		  arrInput[index]=scan.nextInt();
		  int[] arr=new int[arrInput[index]+1];
		  Arrays.fill(arr, 1);
		  int[] primeFact=new int[2];
	      int off=0;
	      int i=2;
	      for(;i<=Math.sqrt(arrInput[index]);i++)
	       {
		      if(arr[i]==1)
		       {
			    //System.out.println("arrInput[index]"+arrInput[index]+" "+i);
		    	if(arrInput[index]%i==0)
			      {
		    		primeFact[off++]=i;
		    	//	System.out.println(primeFact[off-1]);
				    //int temp1=arrInput[index];
		    		/*
		    		  while(temp1%i==0)
					  {
						temp1/=i;
					  }
					 */
					if(off==2)
					{
						break;
					}
			      }
		       }

		     for(int j=i*i;j<=arrInput[index];j+=i)
		      {
			   arr[j]=0;
		      }
		     if(arr[(arrInput[index]/i)]==1)
		     {
		    	 primeFact[off++]=(arrInput[index]/i);
		    	// System.out.println(primeFact[off-1]);
		    	 if(off==2)break;
		     }
	       }
	    arr[0]=0;
	    arr[1]=0;
	    if(off>=2)
	     {
	    	//System.out.println(primeFact[0]+"\n" +primeFact[1]);
	    	d1[d_offset]=primeFact[0];
	    	d2[d_offset]=primeFact[1];
	    	d_offset++;
	     }
	    else
	     {
		    //System.out.println("-1" +"\n"+"-1");
	    	d1[d_offset]=-1;
	    	d2[d_offset]=-1;
	    	d_offset++;
	     }

	  }
	  print(d1);
	  print(d2);
	}
	static void print(int[] d)
	{
		for(int off=0;off<d.length;off++)
		{
		  System.out.print(d[off]+" ");
		}
		System.out.println();
	}

}
 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	static int []primeArr=new int[10000007];
	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  Writer out=new Writer();
	  FaastScanner scan=new FaastScanner(input);
	  factorization();
	  int n=scan.nextInt();

	  int [] l1=new int[n];
	  int [] l2=new int[n];

	  Arrays.fill(l1, -1);
	  Arrays.fill(l2, -1);
	  for(int i=0;i<n;i++)
	  {
	    int inputValue=scan.nextInt();
	    int d1=primeArr[inputValue];
	    int d2=inputValue;
	    while(d2%d1==0)
	     {
	     	d2/=d1;
	     }
	    if(d2>1)
	    {
	    	l1[i]=d1;
	    	l2[i]=d2;
	    }
	  }
	  for(int i=0;i<n;i++)
	  {
	   out.print(l1[i]+" ");
	  }
	  out.println();
	  for(int i=0;i<n;i++)
	  {
		  out.print(l2[i]+" ");
	  }
	  out.exit();
	 }

	static void factorization()
	{
		for(int i = 2; i<10000001; i++) {
			if(primeArr[i]!=0) continue;
			for(int j = 0; j<10000001; j+=i) if(primeArr[j]==0) primeArr[j] = i;
		}

	}
}

 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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

  class Writer {
		private PrintWriter pw;
		public Writer(){
			pw = new PrintWriter(System.out);
		}

		public Writer(String f){
			try {
				pw = new PrintWriter(new FileWriter(f));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

		public void printArray(int[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
		}
		public void printlnArray(int[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
			pw.println();
		}
		public void printArray(long[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
		}
		public void printlnArray(long[] a) {
			for(int i = 0; i<a.length; i++) print(a[i]+" ");
			pw.println();
		}
		public void print(Object o) {
			pw.print(o.toString());
		}
		public void println(Object o) {
			pw.println(o.toString());
		}
		public void println() {
			pw.println();
		}
		public void flush() {
			pw.flush();
		}
		public void exit() {
			pw.close();
		}
	}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  FaastScanner scan=new FaastScanner(input);
	  int n=scan.nextInt();
	  int[] arrInput=new int[n];
	  for(int index=0;index<n;index++)
	  {
		  arrInput[index]=scan.nextInt();
		  int[] arr=new int[arrInput[index]];
		  Arrays.fill(arr, 1);
		  int[] primeFact=new int[2];
	      int off=0;
	      int i=2;
	      for(;i<=(arrInput[index])/2;i++)
	       {
		      if(arr[i]==1)
		       {

		    	if(arrInput[index]%i==0)
			      {

		    		primeFact[off++]=i;
				    int temp1=arrInput[index];
		    		 while(temp1%i==0)
					  {
						temp1/=i;
					  }
					if(off==2)
					{
						break;
					}
			      }
		       }

		     for(int j=i*i;j<arrInput[index];j+=i)
		      {
			   arr[j]=0;
		      }

	       }
	    arr[0]=0;
	    arr[1]=0;
	    if(off>=2)
	     {
	    	System.out.println(primeFact[0]+"\n" +primeFact[1]);
	     }
	    else
	     {
		    System.out.println("-1" +"\n"+"-1");
	     }
	  }
	}

}
 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	static int []primeArr=new int[10000007];
	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  FaastScanner scan=new FaastScanner(input);
	  factorization();
	  //print();
	  int n=scan.nextInt();

	  int [] l1=new int[n];
	  int [] l2=new int[n];

	  Arrays.fill(l1, -1);
	  Arrays.fill(l2, -1);
	  for(int i=0;i<n;i++)
	  {
	    int inputValue=scan.nextInt();
	    int d1=primeArr[inputValue];
	    int d2=inputValue;
	    while(d2%d1==0)
	     {
	     	d2/=d1;
	     }
	    if(d2>1)
	    {
	    	l1[i]=d1;
	    	l2[i]=d2;
	    }
	  }
	  for(int i=0;i<n;i++)
	  {
	   System.out.print(l1[i]+" ");
	  }
	  System.out.println();
	  for(int i=0;i<n;i++)
	  {
		  System.out.print(l2[i]+" ");
	  }
	 }
	static void factorization()
	{
		for(int i = 2; i<10000001; i++) {
			if(primeArr[i]!=0) continue;
			for(int j = 0; j<10000001; j+=i) if(primeArr[j]==0) primeArr[j] = i;
		}

	}

}

 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class TwoDivisors
{

	public static void main(String[] args)
	{
	  InputStream input=System.in;
	  FaastScanner scan=new FaastScanner(input);
	  int n=scan.nextInt();
	  int[] arrInput=new int[n];
	  int [] d1=new int[n];
	  int [] d2=new int[n];

	  int d_offset=0;
	  for(int index=0;index<n;index++)
	  {
		  arrInput[index]=scan.nextInt();
		  int[] arr=new int[arrInput[index]+1];
		  Arrays.fill(arr, 1);
		  arr[0]=0;
		    arr[1]=0;
		  int[] primeFact=new int[2];
	      int off=0;
	      int i=2;
	      for(;i<=Math.sqrt(arrInput[index]);i++)
	       {
		      if(arr[i]==1)
		       {
			//    System.out.println("arrInput[index]"+arrInput[index]+" "+i);
		    	if(arrInput[index]%i==0)
			      {
		    	//	System.out.println("i:"+i);
		    		if(off==0)
		    		{
		    		 primeFact[off]=i;
		    		 off++;
		    		}
		    		else
		    		{
		    			if(primeFact[off-1]!=i)
		    			 {
		    				primeFact[off]=i;
		 		    		off++;
		    			 }
		    		}
		    		// System.out.println(primeFact[off-1]);
					if(off==2)
					{
						break;
					}
			      }
		       }

		     for(int j=i*i;j<=arrInput[index];j+=i)
		      {
			   arr[j]=0;
		      }

		     if(arrInput[index]%i==0&&arr[(arrInput[index]/i)]==1)
		     {
		    	// System.out.println("arr[arrInput[index]/i]:"+arr[(arrInput[index]/i)]+"  "+arrInput[index]/i);

		    	    if(off==0)
		    		{
		    		 primeFact[off]=(arrInput[index]/i);
		    		 off++;
		    		}
		    		else
		    		{
		    			if(primeFact[off-1]!=(arrInput[index]/i))
		    			 {
		    				primeFact[off]=(arrInput[index]/i);
		 		    		off++;
		    			 }
		    		}

		    	 if(off==2)break;
		     }
	       }

	    if(off>=2)
	     {
	    	//System.out.println(primeFact[0]+"\n" +primeFact[1]);
	    	d1[d_offset]=primeFact[0];
	    	d2[d_offset]=primeFact[1];
	    	d_offset++;
	     }
	    else
	     {
		    //System.out.println("-1" +"\n"+"-1");
	    	d1[d_offset]=-1;
	    	d2[d_offset]=-1;
	    	d_offset++;
	     }

	  }
	  print(d1);
	  print(d2);
	}
	static void print(int[] d)
	{
		for(int off=0;off<d.length;off++)
		{
		  System.out.print(d[off]+" ");
		}
		System.out.println();
	}

}
 class FaastScanner
 {
	 BufferedReader br;
	 StringTokenizer st;

	 public FaastScanner(InputStream is)
	  {
		br=new BufferedReader(new InputStreamReader(is));
	  }

	 public FaastScanner(File f)
	  {
		try
		   {
			br=new BufferedReader(new FileReader(f));
		   }
		catch (FileNotFoundException e)
		   {
			e.printStackTrace();
		   }
	 }

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


//package ecr89;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class D {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	static int[] lpf = enumLowestPrimeFactors(10000000);

	void solve()
	{
		int n = ni();
		int[] ra = new int[n];
		int[] rb = new int[n];
		Arrays.fill(ra, -1);
		Arrays.fill(rb, -1);
		for(int i = 0;i < n;i++){
			int x = ni();
			int p = lpf[x];
			int y = x;
			while(y % p == 0){
				y /= p;
			}
			if(y > 1){
				ra[i] = p;
				rb[i] = y;
				assert gcd(ra[i] + rb[i], x) == 1;
			}
		}
		for(int v : ra)out.print(v + " ");
		out.println();
		for(int v : rb)out.print(v + " ");
		out.println();
	}

	public static int gcd(int a, int b) {
		while (b > 0) {
			int c = a;
			a = b;
			b = c % b;
		}
		return a;
	}

	public static int[] roughFactorFast(int n, int[] lpf)
	{
		int[] rf = new int[9];
		int q = 0;
		int pre = -1;
		while(lpf[n] > 0){
			int p = lpf[n];
			if(q == 0 || p != pre){
				rf[q++] = p;
				pre = p;
			}
			n /= p;
		}
		return Arrays.copyOf(rf, q);
	}

	public static int[] enumLowestPrimeFactors(int n) {
		int tot = 0;
		int[] lpf = new int[n + 1];
		int u = n + 32;
		double lu = Math.log(u);
		int[] primes = new int[(int) (u / lu + u / lu / lu * 1.5)];
		for (int i = 2; i <= n; i++)
			lpf[i] = i;
		for (int p = 2; p <= n; p++) {
			if (lpf[p] == p)
				primes[tot++] = p;
			int tmp;
			for (int i = 0; i < tot && primes[i] <= lpf[p] && (tmp = primes[i] * p) <= n; i++) {
				lpf[tmp] = primes[i];
			}
		}
		return lpf;
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception { new D().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.util.*;
import java.io.*;
public class Main{
    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

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

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

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

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

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

        public String readString() {
            int c = snext();
            while (isSpaceChar(c)) {
                c = snext();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(c));
            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

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

    }
    static class OutputWriter {
		private final PrintWriter writer;

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

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

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

		public void printLine(Object...objects) {
			print(objects);
			writer.println();
		}

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

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

		}

    static class IOUtils {

		public static int[] readIntArray(InputReader in, int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = in.nextInt();
            return array;
        }

    }
    static int gcd(int a, int b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
    static int mod = (int)(1e9+7);
    public static long pow(long a,long b)
    {
        long ans = 1;
        while(b> 0)
        {
            if((b & 1)==1){
                ans = (ans*a) % mod;
            }
            a = (a*a) % mod;
            b = b>>1;
        }
        return ans;
    }
    static int mxn = (int)(1e7);
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        //IOUtils io = new IOUtils();
        int[] sieve = new int[mxn+1];
        Arrays.fill(sieve,-1);
        for(int i=2;i*i<sieve.length;i++)
        {
            if(sieve[i]==-1)
            {
                for(int j=i*i;j<sieve.length;j+=i)
                {
                    if(sieve[j]==-1)
                        sieve[j]= i;
                }
            }
        }
        for(int i=1;i<sieve.length;i++)
        {
            if(sieve[i]==-1)
                sieve[i] = i;
        }
        int n = in.nextInt();
        // int[] arr = new int[n];
        StringBuilder sb1 = new StringBuilder();
        StringBuilder sb2 = new StringBuilder();
        for(int i=0;i<n;i++)
        {
            int cur = in.nextInt();
            int prime = sieve[cur];
            int temp = cur;
            while(temp%prime==0)
                temp/=prime;
            if(temp!=1)
            {
                sb1.append(temp + " ");
                sb2.append(prime + " ");
            }
            else{
                sb1.append("-1" + " ");
                sb2.append("-1" + " ");
            }
        }
        out.printLine(sb1);
        out.printLine(sb2);
        out.flush();
        out.close();
    }
}


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

//Sub_To_Errichto
public class Main {
    //static final long MOD = 1000000007L;
    static final long MOD = 998244353L;
    static final int INF = 50000000;
    static final int NINF = -500000000;

    static final long BASE = 31L;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int Q = sc.ni();
        int T = 10000000;
        boolean[] sieve = new boolean[T+1];
        Arrays.fill(sieve,true);
        for (int i = 2; i <= T; i++) {
        	if (sieve[i]) {
        		for (int j = 2*i; j <= T; j += i)
        			sieve[j] = false;
        	}
        }
        ArrayList<Integer> primes = new ArrayList<Integer>();
        for (int i = 2; i <= T; i++) {
        	if (sieve[i])
        		primes.add(i);
        }
        int[][] ans = new int[Q][2];
        for (int q = 0; q < Q; q++) {
        	int N = sc.ni();
        	Arrays.fill(ans[q], -1);
        	if (sieve[N])
        		continue;
        	int prime = 1;
        	for (int p: primes) {
        		if (p*p > N) break;
        		if (N%p==0) {
        			prime = p;
        			break;
        		}
        	}

        	if (prime == 1) {
        		continue;
        	}

        	int X = N;
        	while (X % prime == 0) {
        		X /= prime;
        	}
        	int Y = N/X;
        	if (X > 1 && Y > 1) {
        		ans[q][0] = X;
        		ans[q][1] = Y;
        	}
        }

        for (int j = 0; j < 2; j++) {
        	for (int i = 0; i < Q; i++) {
        		pw.print(ans[i][j] + " ");
        	}
        	pw.println();
        }

        pw.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            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 ni() {
            return Integer.parseInt(next());
        }

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

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

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


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

//Sub_To_Errichto
public class Main {
    //static final long MOD = 1000000007L;
    static final long MOD = 998244353L;
    static final int INF = 50000000;
    static final int NINF = -500000000;

    static final long BASE = 31L;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int Q = sc.ni();
        int T = 10000000;
        boolean[] sieve = new boolean[T+1];
        Arrays.fill(sieve,true);
        for (int i = 2; i <= T; i++) {
        	if (sieve[i]) {
        		for (int j = 2*i; j <= T; j += i)
        			sieve[j] = false;
        	}
        }
        int[] primes = new int[664579];
        int ind = 0;
        for (int i = 2; i <= T; i++) {
        	if (sieve[i]) {
        		primes[ind] = i;
        		ind++;
        	}
        }

        int[][] ans = new int[Q][2];
        for (int q = 0; q < Q; q++) {
        	int N = sc.ni();
        	Arrays.fill(ans[q], -1);
        	if (sieve[N])
        		continue;
        	int prime = 1;
        	for (int p: primes) {
        		if (p*p > N) break;
        		if (N%p==0) {
        			prime = p;
        			break;
        		}
        	}

        	if (prime == 1) {
        		continue;
        	}

        	int X = N;
        	while (X % prime == 0) {
        		X /= prime;
        	}
        	int Y = N/X;
        	if (X > 1 && Y > 1) {
        		ans[q][0] = X;
        		ans[q][1] = Y;
        	}
        }

        for (int j = 0; j < 2; j++) {
        	for (int i = 0; i < Q; i++) {
        		pw.print(ans[i][j] + " ");
        	}
        	pw.println();
        }

        pw.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            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 ni() {
            return Integer.parseInt(next());
        }

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

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

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


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

//Sub_To_Errichto
public class Main {
    //static final long MOD = 1000000007L;
    static final long MOD = 998244353L;
    static final int INF = 50000000;
    static final int NINF = -500000000;

    static final long BASE = 31L;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int Q = sc.ni();
        int T = 10000000;
        boolean[] sieve = new boolean[T+1];
        Arrays.fill(sieve,true);
        for (int i = 2; i <= T; i++) {
        	if (sieve[i]) {
        		for (int j = 2*i; j <= T; j += i)
        			sieve[j] = false;
        	}
        }
        ArrayList<Integer> primes = new ArrayList<Integer>();
        for (int i = 2; i <= T; i++) {
        	if (sieve[i])
        		primes.add(i);
        }
        int[][] ans = new int[Q][2];
        for (int q = 0; q < Q; q++) {
        	int N = sc.ni();
        	Arrays.fill(ans[q], -1);
        	int prime = 1;
        	for (int p: primes) {
        		if (p*p > N) break;
        		if (N%p==0) {
        			prime = p;
        			break;
        		}
        	}

        	if (prime == 1) {
        		continue;
        	}

        	int X = N;
        	while (X % prime == 0) {
        		X /= prime;
        	}
        	int Y = N/X;
        	if (X > 1 && Y > 1) {
        		ans[q][0] = X;
        		ans[q][1] = Y;
        	}
        }

        for (int j = 0; j < 2; j++) {
        	for (int i = 0; i < Q; i++) {
        		pw.print(ans[i][j] + " ");
        	}
        	pw.println();
        }

        pw.close();
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            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 ni() {
            return Integer.parseInt(next());
        }

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

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

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


import java.io.*;
import java.util.*;

public class Main{
	static int[]lp;
	static void sieveLinear(int N)
	{
		ArrayList<Integer> primes = new ArrayList<Integer>();
		lp = new int[N + 1];								//lp[i] = least prime divisor of i
		for(int i = 2; i <= N; ++i)
		{
			if(lp[i] == 0)
			{
				primes.add(i);
				lp[i] = i;
			}
			int curLP = lp[i];
			for(int p: primes)//all primes smaller than or equal my lowest prime divisor
				if(p > curLP || p * 1l * i > N)
					break;
				else
					lp[p * i] = p;
		}
	}
	static int gcd(int a, int b) {

		if (b == 0)
			return a;
		return gcd(b, a % b);
	}
	static void main() throws Exception{
		int maxn=(int)1e7;
		sieveLinear(maxn);
		int n=sc.nextInt();
		int[]in=sc.intArr(n);
		int[][]ans=new int[2][n];
		for(int i=0;i<n;i++) {
			int x=in[i];
			LinkedList<Integer>primeD=new LinkedList<>();
			while(x>1) {
				int lowestDivisor=lp[x];
				primeD.add(lowestDivisor);
				while(x%lowestDivisor==0) {
					x/=lowestDivisor;
				}
			}
			if(primeD.size()==1) {
				ans[0][i]=-1;
				ans[1][i]=-1;

			}
			else {
				ans[0][i]=primeD.poll();
				ans[1][i]=primeD.poll();
				while(!primeD.isEmpty()) {
					ans[1][i]*=primeD.poll();
				}
			}
		}
		for(int i:ans[0])pw.print(i+" ");
		pw.println();
		for(int i:ans[1])pw.print(i+" ");
		pw.println();
	}
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
//		int tc=sc.nextInt();
//		while(tc-->0)
			main();
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


//package div2_646;

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

public class A {
    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;
        }
    }
    //static int[][] d = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};
    static final int MAXN = 10000000+1;

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

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

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

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

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

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

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

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();

        sieve();
        String s1="",s2="";

//        for(int num : getFactorization(32)){
//            System.out.print(num+" ");
//        }

        for(int i=0;i<n;i++){
            int num = sc.nextInt();
            ArrayList<Integer> f =  getFactorization(num);
            if(f.size()==1){
                s1+="-1 ";
                s2+="-1 ";
            }
            else{
                int prod = 1;
                for(int j=1;j<f.size();j++){
                    prod *= f.get(j);
                }
                s1 += f.get(0) +" ";
                s2 += prod +" ";
            }
        }
        System.out.println(s1);
        System.out.println(s2);

    }

}


//package div2_646;

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

public class A {
    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;
        }
    }
    //static int[][] d = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};
    static final int MAXN = 10000000+1;

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

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

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

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

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

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

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

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();

        sieve();
        String s1="",s2="";

//        for(int num : getFactorization(32)){
//            System.out.print(num+" ");
//        }

        for(int i=0;i<n;i++){
            int num = sc.nextInt();
            ArrayList<Integer> f =  getFactorization(num);
            if(f.size()==1){
                s1+="-1 ";
                s2+="-1 ";
            }
            else{
                int prod = 1;
                for(int j=1;j<f.size();j++){
                    prod *= f.get(j);
                }
                s1 += f.get(0) +" ";
                s2 += prod +" ";
            }
        }
        System.out.println(s1);
        System.out.println(s2);

    }

}


//package div2_646;

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

public class A {
    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;
        }
    }
    //static int[][] d = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};
    static final int MAXN = 10000000+1;

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

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

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

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

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

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

    // A O(log n) function returning primefactorization
    // by dividing by smallest prime factor at every step
    static ArrayList<Integer> getFactorization(int x)
    {
        ArrayList<Integer> ret = new ArrayList<Integer>();
        while (x != 1)
        {
            if(ret.isEmpty()||ret.get(ret.size()-1)!=spf[x]) {
                ret.add(spf[x]);
            }
            x = x / spf[x];
        }
        return ret;
    }
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();

        sieve();
        String s1="",s2="";

//        for(int num : getFactorization(32)){
//            System.out.print(num+" ");
//        }
        int[] a = new int[n];
        int[] b = new int[n];

        for(int i=0;i<n;i++){
            int num = sc.nextInt();
            ArrayList<Integer> f =  getFactorization(num);
            if(f.size()==1){
                a[i] = -1;
                b[i] = -1;
            }
            else{
                int prod = 1;
                for(int j=1;j<f.size();j++){
                    prod *= f.get(j);
                }
                a[i] = f.get(0);
                b[i] = prod;
            }
        }
        for(int i=0;i<n;i++){
            out.print(a[i]+" ");
        }
        out.println();
        for(int i=0;i<n;i++){
            out.print(b[i]+" ");
        }
        out.println();

        out.flush();
        out.close();

    }

}


//package div2_646;

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

public class A {
    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;
        }
    }
    //static int[][] d = new int[][]{{0,1},{1,0},{-1,0},{0,-1}};
    static final int MAXN = 10000000+1;

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

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

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

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

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

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

    // A O(log n) function returning primefactorization
    // by dividing by smallest prime factor at every step
    static ArrayList<Integer> getFactorization(int x)
    {
        ArrayList<Integer> ret = new ArrayList<Integer>();
        while (x != 1)
        {
            if(ret.isEmpty()||ret.get(ret.size()-1)!=spf[x]) {
                ret.add(spf[x]);
            }
            x = x / spf[x];
        }
        return ret;
    }
    static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();

        sieve();
        String s1="",s2="";

//        for(int num : getFactorization(32)){
//            System.out.print(num+" ");
//        }
        int[] a = new int[n];
        int[] b = new int[n];

        for(int i=0;i<n;i++){
            int num = sc.nextInt();
            ArrayList<Integer> f =  getFactorization(num);
            if(f.size()==1){
                a[i] = -1;
                b[i] = -1;
            }
            else{
                int prod = 1;
                for(int j=1;j<f.size();j++){
                    prod *= f.get(j);
                }
                a[i] = f.get(0);
                b[i] = prod;
            }
        }
        for(int i=0;i<n;i++){
            System.out.print(a[i]+" ");
        }
        System.out.println();
        for(int i=0;i<n;i++){
            System.out.print(b[i]+" ");
        }
        System.out.println();

    }

}


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

import static java.lang.Math.*;

public class Solution implements Runnable {
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();

			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}

				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

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

		public int nextInt() {
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-') {
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;

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

		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

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

	public static void main(String args[]) throws Exception {
		new Thread(null, new Solution(), "Main", 1 << 27).start();
	}

	static class Pair {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x * 7 + (y * 3 + 5 * (y - x));
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			Pair other = (Pair) obj;
			if (x != other.x && y != other.y) {
				return false;
			}
			return true;
		}
	}

	static boolean [] sieveOfEratosthenes(int n) {
		//Prints prime nos till n
		boolean prime[] = new boolean[n + 1];
		for (int i = 0; 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;
			}
		}
		return prime;
	}

	public void run() {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		boolean prime[]=sieveOfEratosthenes(10000000);
		int n=in.nextInt();
		int d1[]=new int[n];
		int d2[]=new int[n];
		for(int i=0;i<n;i++)
		{
			int a=in.nextInt();
			if(prime[a])
			{
				d1[i]=-1;
				d2[i]=-1;
			}
			else
			{
				if(a%5==0)
				{
					d1[i]=2;
					d2[i]=5;
				}
				else
				{
					d1[i]=2;
					d2[i]=3;
				}
			}
		}
		for(int i=0;i<n;i++)
			w.print(d1[i]+" ");
		w.println();
		for(int i=0;i<n;i++)
			w.print(d2[i]+" ");
		w.flush();
		w.close();
	}
}


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

import static java.lang.Math.*;

public class Solution implements Runnable {
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();

			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}

				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

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

		public int nextInt() {
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-') {
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;

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

		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

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

	public static void main(String args[]) throws Exception {
		new Thread(null, new Solution(), "Main", 1 << 27).start();
	}

	static class Pair {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x * 7 + (y * 3 + 5 * (y - x));
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			Pair other = (Pair) obj;
			if (x != other.x && y != other.y) {
				return false;
			}
			return true;
		}
	}

	static int pf[] = new int[10000001];

	static void sieve()
    {
        for (int i=1; i<10000001; i++)
            pf[i] = i;

        for (int i=4; i<10000001; i+=2)
            pf[i] = 2;

        for (int i=3; i*i<10000001; i++)
        {
            if (pf[i] == i)
            {
                for (int j=i*i; j<10000001; j+=i)
                {
                	if (pf[j]==j)
                        pf[j] = i;
                }
            }
        }
    }

	public void run() {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		sieve();
		int d1[]=new int[n];
		int d2[]=new int[n];
		for(int i=0;i<n;i++)
		{
			int a=in.nextInt();
			int x=a;
			if(pf[a]==a)
				d1[i]=d2[i]=-1;
			else
			{
				d1[i]=pf[a];
				while (a != 1)
		        {
		            a = a / pf[a];
		            if(x%(d1[i]+pf[a])!=0 && pf[a]!=d1[i])
		            {
		            	d2[i]=pf[a];
		            	break;
		            }
		        }
				if(a==1)
					d1[i]=d2[i]=-1;
			}
		}
		for(int i=0;i<n;i++)
			w.print(d1[i]+" ");
		w.println();
		for(int i=0;i<n;i++)
			w.print(d2[i]+" ");
		w.flush();
		w.close();
	}
}


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

import static java.lang.Math.*;

public class Solution implements Runnable {
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();

			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}

				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

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

		public int nextInt() {
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-') {
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;

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

		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

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

	public static void main(String args[]) throws Exception {
		new Thread(null, new Solution(), "Main", 1 << 27).start();
	}

	static class Pair {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x * 7 + (y * 3 + 5 * (y - x));
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			Pair other = (Pair) obj;
			if (x != other.x && y != other.y) {
				return false;
			}
			return true;
		}
	}

	static int pf[] = new int[10000001];

	static void sieve()
    {
        for (int i=1; i<10000001; i++)
            pf[i] = i;

        for (int i=4; i<10000001; i+=2)
            pf[i] = 2;

        for (int i=3; i*i<10000001; i++)
        {
            if (pf[i] == i)
            {
                for (int j=i*i; j<10000001; j+=i)
                {
                	if (pf[j]==j)
                        pf[j] = i;
                }
            }
        }
    }
    static List<Integer> getFactorization(int x)
    {
        List<Integer> ret = new Vector<>();
        HashSet<Integer> H=new HashSet<Integer>();
        while (x != 1 && ret.size()<2)
        {
        	if(!H.contains(pf[x]))
        		ret.add(pf[x]);
        	H.add(pf[x]);
            x = x / pf[x];
        }
        return ret;
    }

	public void run() {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		sieve();
		int d1[]=new int[n];
		int d2[]=new int[n];
		for(int i=0;i<n;i++)
		{
			int a=in.nextInt();
			List<Integer> A=new ArrayList<Integer>(getFactorization(a));
			if(A.size()==0 || A.size()==1)
				d1[i]=d2[i]=-1;
			else
			{
				d1[i]=A.get(0);
				d2[i]=A.get(1);
			}
		}
		for(int i=0;i<n;i++)
			w.print(d1[i]+" ");
		w.println();
		for(int i=0;i<n;i++)
			w.print(d2[i]+" ");
		w.flush();
		w.close();
	}
}


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

import static java.lang.Math.*;

public class Solution implements Runnable {
	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;
		private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

		public int read() {
			if (numChars == -1)
				throw new InputMismatchException();

			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}

				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

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

		public int nextInt() {
			int c = read();

			while (isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-') {
				sgn = -1;
				c = read();
			}

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

			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;

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

		public double nextDouble() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.') {
				c = read();
				double m = 1;
				while (!isSpaceChar(c)) {
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next() {
			return readString();
		}

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

	public static void main(String args[]) throws Exception {
		new Thread(null, new Solution(), "Main", 1 << 27).start();
	}

	static class Pair {
		int x, y;

		Pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + x * 7 + (y * 3 + 5 * (y - x));
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj) {
				return true;
			}
			if (obj == null) {
				return false;
			}
			if (getClass() != obj.getClass()) {
				return false;
			}
			Pair other = (Pair) obj;
			if (x != other.x && y != other.y) {
				return false;
			}
			return true;
		}
	}

	static int pf[] = new int[10000001];

	static void sieve()
    {
        for (int i=1; i<10000001; i++)
            pf[i] = i;

        for (int i=4; i<10000001; i+=2)
            pf[i] = 2;

        for (int i=3; i*i<10000001; i++)
        {
            if (pf[i] == i)
            {
                for (int j=i*i; j<10000001; j+=i)
                {
                	if (pf[j]==j)
                        pf[j] = i;
                }
            }
        }
    }

	public void run() {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		sieve();
		int d1[]=new int[n];
		int d2[]=new int[n];
		for(int i=0;i<n;i++)
		{
			int a=in.nextInt();
			if(pf[a]==a)
				d1[i]=d2[i]=-1;
			else
			{
				d1[i]=pf[a];
				while (a%d1[i]==0)
		        {
		            a/=d1[i];
		        }
				d2[i]=a;
				if(a==1)
					d1[i]=d2[i]=-1;
			}
		}
		for(int i=0;i<n;i++)
			w.print(d1[i]+" ");
		w.println();
		for(int i=0;i<n;i++)
			w.print(d2[i]+" ");
		w.flush();
		w.close();
	}
}


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

public class d {

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

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

				for(int d11 = 1 ; d11 < prime.size()  ;d11++) {
					a*=prime.get(d11);
				}
				if(a!=1) {
					d1[i]= prime.get(0);
					d2[i]= a;
				}
			}
			for(int i : d1)out.print(i +" ");
			out.println();
			for(int i : d2)out.print(i +" ");

		}

		out.flush();
	}

	static final int MAXN = 10000001;

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

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

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

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

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

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

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

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

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

	static class FastScanner {
		BufferedReader in;
		StringTokenizer st;

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

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

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

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

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