#include <iostream>
#include <algorithm>
using namespace std;
void divide(int x) {
for (int i = 2; i <= x / i; i ++ )
if (x % i == 0) { //枚举的都是质因子,因为已经把1到i-1之间的所有质因子都除干净了
int s = 0;
while (x % i == 0) x /= i, s ++ ;
cout << i << ' ' << s << endl;
}//n中最多包含一个大于sqrt(n)的质因子
if (x > 1) cout << x << ' ' << 1 << endl;//最后处理
cout << endl;
}
int main() {
int n;
cin >> n;
while (n -- ) {
int x;
cin >> x;
divide(x);
}
return 0;
}