import java.util.*; public class Main { static int next(int a){ int p = (a/100)%10, q = (a/10)%10, r = a%10; int s = (p+q+r)%10; return 100*q+10*r+s; } public static void main(String[] args) throws Exception{ final ContestScanner sc = new ContestScanner(); final ContestPrinter pr = new ContestPrinter(); int p = sc.nextInt()%10, q = sc.nextInt()%10, r = sc.nextInt()%10; int a = 100*p+10*q+r; int[][] dp = new int[1000][62]; for(int i=0; i<1000; i++) dp[i][0] = next(i); for(int d=1; d<62; d++)for(int i=0; i<1000; i++) dp[i][d] = dp[dp[i][d-1]][d-1]; long K = sc.nextLong()-3; for(int d=0; d<62; d++) if((K&(1L<= LONG_MAX_TENTHS) { if (n == LONG_MAX_TENTHS) { if (minus) { if (digit <= LONG_MIN_LAST_DIGIT) { n = -n * 10 - digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } else { if (digit <= LONG_MAX_LAST_DIGIT) { n = n * 10 + digit; b = readByte(); if (!isPrintableChar(b)) { return n; } else if (b < '0' || '9' < b) { throw new NumberFormatException( String.format("%d%s... is not number", n, Character.toString(b)) ); } } } } throw new ArithmeticException( String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit) ); } n = n * 10 + digit; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } public long[] nextLongArray(int length){ long[] array = new long[length]; for(int i=0; i