#include using namespace std; using LL = long long; using ULL = unsigned long long; constexpr int MOD = 10; struct M { LL p[3][3] = { {1, 1, 1}, {1, 0, 0}, {0, 1, 0}, }; M mul(M b, LL m) { M c; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { c.p[i][j] = 0; for (int k = 0; k < 3; k++) { c.p[i][j] += (this->p[i][k] * b.p[k][j]) % m; } } } return c; } }; struct E : M { LL p[3][3] = { {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, }; }; M pow(M, LL, LL); int main() { LL p, q, r, K; cin >> p >> q >> r >> K; M A, B = pow(A, K - 3, MOD); LL ans = 0; ans = (ans + B.p[0][0] * r) % MOD; ans = (ans + B.p[0][1] * q) % MOD; ans = (ans + B.p[0][2] * p) % MOD; cout << ans << endl; } M pow(M a, LL b, LL m) { if (b == 0) return E(); if (b == 1) return M(); M ret = pow(a, b / 2, m); ret = ret.mul(ret, m); if (b % 2 == 1) ret = ret.mul(a, m); return ret; }