import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n,m,l,k,b = na() a = [0] * l a[0] = 1 % b a[1 % l] = 1 % b f = [0] * l f[0] = 1 #print(f, a) while n: if n % 2: nf = [0] * l for i in range(l): for j in range(l): if i+j >= l: nf[i+j-l] += f[i] * a[j] % b * m % b else: nf[i+j] += f[i] * a[j] % b nf[(i+j)%l] %= b f = nf na = [0] * l for i in range(l): for j in range(l): if i+j >= l: na[i+j-l] += a[i] * a[j] % b * m % b else: na[i+j] += a[i] * a[j] % b na[(i+j)%l] %= b a = na #print(f, a) n//=2 #print(f) print(f[k] % b)