#include using namespace std; #define rep(i,n) for (int i = 0; i < (int)(n); ++i) #define Rep(i,a,b) for (int i = a; i < b; ++i) #define rRep(i,a,b) for (int i = a; i > b; --i) #define fore(i,a) for(auto &i:a) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define Unique(v) v.erase(unique(v.begin(), v.end()), v.end()); #define Bit(x,i) (((x)>>(i))&1) #define fi first #define se second using ll = long long; using vi = vector; using vll = vector; using vvi = vector; using vvll = vector; using pii = pair; using pll = pair; template auto mvec(const size_t (&d)[n], const T& init) noexcept { if constexpr (idx < n) return std::vector(d[idx], mvec(d, init)); else return init; } template auto mvec(const size_t (&d)[n]) noexcept { return mvec(d, T{}); } void print(){ cout << '\n'; } template void print(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; } template constexpr auto Min(T... a){ return min(initializer_list>{a...}); } template constexpr auto Max(T... a){ return max(initializer_list>{a...}); } template bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (b= mod) x -= mod; return *this; } modint& operator-=(const modint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } modint& operator*=(const modint& a) { (x *= a.x) %= mod; return *this; } modint operator+(const modint& a) const { modint res(*this); return res+=a; } modint operator-(const modint& a) const { modint res(*this); return res-=a; } modint operator*(const modint& a) const { modint res(*this); return res*=a; } modint pow(ll t) const { if (!t) return 1; modint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } modint inv() const { return pow(mod-2); } modint& operator/=(const modint& a) { return (*this) *= a.inv(); } modint operator/(const modint& a) const { modint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const modint& m){ os << m.x; return os; } }; using mat = vector>; using vec = vector; mat dot(mat &A, mat &B) { mat ret(A.size(), vec(B[0].size())); for(int i = 0; i < (int)A.size(); ++i) { for(int k = 0; k < (int)B.size(); ++k) { for(int j = 0; j < (int)B[0].size(); ++j) { ret[i][j] = ret[i][j] + A[i][k] * B[k][j]; } } } return ret; } mat mat_pow(mat A, long long n) { mat res(A.size(), vec(A.size())); for(int i = 0; i < (int)A.size(); i++) { res[i][i] = 1; } while(n > 0) { if(n & 1) res = dot(A, res); A = dot(A, A); n >>= 1; } return res; } int main() { ll p, q, r, K; cin >> p >> q >> r >> K; p %= 10; q %= 10; r %= 10; mat A = {{1, 1, 1}, {1, 0, 0}, {0, 1, 0}}; A = mat_pow(A, K-3); modint ans = A[0][0] * r + A[0][1] * q + A[0][2] * p; cout << ans << endl; }