#include<stdio.h>
#include<cstring>
#include<math.h>
#define MAX 65537
int prime[6542],len=0,divisor[1000],count[1000];
void set_prime(){
prime[len++]=2 ;
for (int i=3 ;i<MAX;i+=2 ){
bool ok=1 ;
for (int j=0 ,k=(int)(sqrt(i)) ;prime[j]<=k ;j++ )if (i%prime[j]==0){
ok=0 ;
break ;
}
if (ok)prime[len++]=i ;
}
}
int pd(int n){
int x=0;
for(int i=0,k=(int)(sqrt(n));prime[i]<=k;i++)
{
if(n%prime[i]==0){
divisor[x]=prime[i];
count[x]=0;
while(n%prime[i]==0){count[x]++,n/=prime[i];}
x++;
}
}
if(n!=1) divisor[x]=n,count[x]=1,x++;
return x;
}
int sum(int x,int y){
int ans=1;
while(y){
if(y%2) ans=ans*x;
x*=x;
y/=2;
}
return ans;
}
int main(){
set_prime() ;
char c[1000];
while(gets(c)){
if(strcmp(c,"0")==0) break;
int x,a=0,b=0,n=1;
bool end=false;
for(int i=0;i<strlen(c);i++)
{if(c[i]>='0'&&c[i]<='9'&&end==false) a=a*10+c[i]-'0';
else if(c[i]>='0'&&c[i]<='9'&&end==true) b=b*10+c[i]-'0';
else if(a!=0&&b!=0) n*=(int)pow(a,b),a=0,b=0,end=false;
else end=true;
}
if(a!=0&&b!=0) n*=sum(a,b);
x=pd(n-1);
for(int i=x-1;i>=0;i--) printf("%d %d ",divisor[i],count[i]);
printf("\n");
}
}