var n,s,i,a,b:longint; t:boolean; begin readln(a); for b:=1 to a do begin readln(n); write(n,' = '); t:=false; for i:=2 to n do begin s:=0; while n mod i=0 do begin inc(s); n:=n div i; end; if s>0 then begin if t then write(' * '); t:=true;
if s=1 then write(i) else write(i,'^',s); end; end; writeln; end; end.