from math import sqrt N,M,mod=map(int,input().split()) A=pow(M,N,mod) ANS=[] while A>0: k=int(sqrt(A)) ANS.append(k) A-=k*k A%=mod while len(ANS)<6: ANS.append(0) print(*ANS)