def resolve(): m = 1_000_000_007 a,b,c,d = map(int,input().split()) n= int(input()) div,rem = divmod(n,8) if rem == 0: tmp = (b+d)%m elif rem == 1: tmp = (2*b)%m elif rem == 2: tmp = (2*(b-c))%m elif rem == 3: tmp = (-4*c)%m elif rem == 4: tmp = (-4*(a+c))%m elif rem == 5: tmp = (-8*a)%m elif rem == 6: tmp = (-8*(a-d))%m else: tmp = (16*d)%m print((tmp*pow(16,div,m))%m) resolve()