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