a = int(input())
b = int(input())
n = int(input())

if n <= 100:
    for i in range(3, n + 1):
        c = (a ** 2 + b ** 2) % 10
        a, b = b, c
    print(c)
else:
    z = [a * 10 + b]
    for i in range(3, 100):
        c = (a ** 2 + b ** 2 ) % 10
        zn = b * 10 + c
        if zn in z:
            n1, n2 = z.index(zn), i - 2
            break
        z.append(zn)
        a, b = b, c
     
    p = n2 - n1
    z = z[n1:]
    z = [z[-1]] + z[:-1]
    if n1 > 0:
        n -= n1
    n = (n) % p
    print(z[n] // 10)
    