#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ull M=1000000007;

ull powm(ull a,ull i){
  if(i==0) return 1;
  ull r=powm(a*a%M,i/2);
  if(i%2==1) r=r*a%M;
  return r;
}

ll A,B,C,D,N;

int main(){
  cin>>A>>B>>C>>D>>N;
  A=(A+M*100)%M;
  B=(B+M*100)%M;
  C=(C+M*100)%M;
  D=(D+M*100)%M;
  ull Mul = powm(16,N/8); N%=8;
  if(N%8>=4){
    Mul=Mul*4%M;
    swap(A,B); A=(M-A)%M; B=(M-B)%M;
    swap(C,D); C=(M-C)%M; D=(M-D)%M;
    N-=4;
  }
  if(N%4>=2){
    Mul=Mul*2%M;
    swap(A,C); swap(B,D);
    swap(A,B); A=(M-A)%M; B=(M-B)%M;
    N-=2;
  }
  if(N%2==1){
    cout<<(B*2*Mul%M)<<"\n";
  }
  else{
    cout<<((B+D)*Mul%M)<<"\n";
  }
  return 0;
}