def matmul(A,B,mod): res = [[0]*len(B[0]) for _ in [None]*len(A)] for i, resi in enumerate(res): for k, aik in enumerate(A[i]): for j,bkj in enumerate(B[k]): resi[j] += aik*bkj resi[j] %= mod return res def matpow(A,p,mod): if p%2: return matmul(A, matpow(A,p-1,mod),mod) elif p > 0: b = matpow(A,p//2,mod) return matmul(b,b,mod) else: return [[int(i==j) for j in range(len(A))] for i in range(len(A))] mod=10000 def calc(x,m): if x==0: return 0 if m==0: return 0 mat=[[x,1], [1,0]] if m==1: return 0 if m==2: return x matp=matpow(mat,m-2,mod) res=matmul(matp,[[x],[1]],mod) ans=res[0][0] if m%2==1: ans-=1 return ans%mod s=int(input()) m=int(input()) bit=int(input()) n=10000 nxt=[0]*10000 for i in range(n): nxt[i]=calc(i,m) table=[] table.append(nxt) for i in range(60): nxt=[0]*n for j in range(n): nxt[j]=table[-1][table[-1][j]] table.append(nxt) now=s for i in range(60): if (bit>>i)&1: now=table[i][now] ans=str(now) if now==0: print('0'*4) else: print('0'*(4-len(ans))+ans)