mseq a b = 
    let a' = (a * b) `mod` 10
    in
        a:(mseq a' b)

pow n i =
    let n' = n `mod` 10
        s@(h:t) = take 10 $ mseq n' n'
        r = h:(takeWhile (/= h) t)
        l = length r
        m = (i-1) `mod` l
    in
        r!!m

ans [n,m,k] = 
    let n' = n `mod` 10
        nm = pow n' m
        s@(h:t) = take 10 $ mseq n' nm
        r = h:(takeWhile (/= h) t)
        l = length r
        nn = k `mod` l
        mm = k `div` l
        a = mm * (sum r) + (sum $ take nn s)
    in  
        a

main = do
    l <- getLine
    let i = map read $ words l :: [Int]
        o = ans i
    print o


