#include using namespace std; using ll = long long; void pow(ll a, ll b, ll c, ll d, ll i, ll &ra, ll &rb, ll &rc, ll &rd) { while(i){ if (i & 1) { ll ta = ra * a + rb * c; ll tb = ra * b + rb * d; ll tc = rc * a + rd * c; ll td = rc * b + rd * d; ra = ta; rb = tb; rc = tc; rd = td; } ll ta = a * a + b * c; ll tb = a * b + b * d; ll tc = a * c + c * d; ll td = b * c + d * d; a = ta; b = tb; c = tc; d = td; i >>= 1; } return; } const ll mod = 1000000000 + 7; int main() { ll a, b, c, d, n; cin >> a >> b >> c >> d >> n; ll ra = 1, rb = 0, rc = 0, rd = 1; pow(1, -1, 1, 1, n, ra, rb, rc, rd); ra += rc; rb += rd; if (ra >= 0) { ra %= mod; ra *= b; ra %= mod; } else { ra %= mod; ra *= a; ra %= mod; } if(rb >= 0) { rb %= mod; rb *= d; rb %= mod; } else { rb %= mod; rb *= c; rb %= mod; } ra += mod; ra %= mod; rb += mod; rb %= mod; cout << (ra + rb) % mod << endl; }