#include <iostream>
using namespace std;
int main(){
int n;
cin >> n;
for (int i = 1; i <= n; i ++ ){
int t;
cin >> t;
for(int j = 2;j <= t / j;j++){
if(t % j == 0){
int s = 0;
while(t%j == 0){
t /= j;
s ++;
}
cout << j << ' ' << s <<endl;
}
}
if(t > 1) cout << t << ' ' << 1 << endl;
cout << endl;
}
return 0;
}