#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,a;
cin>>n;
while(n--)
{
scanf("%d",&a);
if(a%2==0)
{
int s=0;
while(a%2==0)
{
s++;
a/=2;
}
printf("2 %d\n",s);
}
for(int i=3;i<=a/i;i+=2)
if(a%i==0)
{
int s=0;
while(a%i==0)
{
s++;
a/=i;
}
printf("%d %d\n",i,s);
}
if(a>1) printf("%d 1\n",a);
cout<<endl;
}
return 0;
}