#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;

    for (long long i=3; i <= n; i++)
    {
        c = (a * a + b * b) % 10;
        a = b;
		b = c;
	}
	cout << c;

	return 0;
}
