#include <iostream>
#include <vector>
#include <algorithm>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

int main(int argc, char** argv) {
    long long a, b, n, c;
    cin >> a >> b >> n;

if (n <= 100)
{
    for (int i=3; i <= n; i++)
    {
        c = (a * a + b * b) % 10;
        a = b;
		b = c;
	}
	cout << c;
}
else
{
    vector <int> z;
    int zn, n1, n2;
    z.push_back(a * 10 + b);
    for (int i = 3; i < 100; i++)
    {
        c = (a * a + b * b ) % 10;
        zn = b * 10 + c;
        if (find(z.begin(), z.end(), zn) != z.end())
        {
            n1 = find(z.begin(), z.end(), zn) - z.begin();
            n2 = i - 2;
            break;
        }
        z.push_back(zn);
        a = b;
		b = c;
    }
    int p = n2 - n1;
    z.erase(z.begin(), z.begin() + n1);
    rotate(z.begin(), z.end() - 1, z.end());
    if (n1 > 0)
        n -= n1;
    n = (n) % p;    
    cout << z[n] / 10;
}
	return 0;
}
