#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n--){
int x;
cin>>x;
for(int i = 2, cnt; i <= x / i; i++){
cnt = 0;
while(x % i == 0){
cnt++;
x /= i;
}
if(cnt)
cout<<i<<" "<<cnt<<endl;
}
if(x > 1)
cout<<x<<" "<<1<<endl;
cout<<endl;
}
return 0;
}