#include <iostream>
#include <vector>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<deque>
#include<math.h>
#include<set>
#include<string>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(ll i = 0;i<n;i++)
#define req(i,n) for(ll i = 1;i<=n;i++)
#define rrep(i,n) for(int i = n-1;i>=0;i--)
#define ALL(a) a.begin(),a.end()
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef long double d;
const ll INF = 1<<61;
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int main() {
	int a, b, c; cin >> a >> b >> c; int o = a % 10,ans;
    if (o == 1 || o == 0 || o == 5 || o == 6) ans = a % 10;
    else if (o == 2 || o == 7 || o == 8) {
        int t = mod_pow(b, c, 4);
        if (o == 2) {
            if (t == 0)ans = 6;
            else if (t == 1)ans = 2;
            else if (t == 2)ans = 4;
            else ans = 8;
        }
        else if (o == 7) {
            if (t == 0)ans = 1;
            else if (t == 1)ans = 7;
            else if (t == 2)ans = 9;
            else ans = 3;
        }
        else {
            if (t == 0)ans = 6;
            else if (t == 1)ans = 8;
            else if (t == 2)ans = 4;
            else ans = 2;
        }
    }
    else if (o == 4 || o == 9) {
        int t = mod_pow(b, c, 2);
        if (o == 4) {
            if (t == 0) ans = 6;
            else ans = 4;
        }
        else {
            if (t == 0)ans = 1;
            else ans = 9;
        }
    }
    else {
        int t = mod_pow(b, c, 3);
        if (t == 0) ans = 7;
        else if (t == 1)ans = 3;
        else ans = 9;
    }cout << ans << endl;
}
#include <stdio.h>

long long A, B, C;
long long d[10][4];

int main() {
	long long i, u;

	for (i = 0; i < 10; i++) for (d[i][0] = i, u = 1; u < 4; u++) d[i][u] = (d[i][u - 1] * i) % 10;
	scanf("%lld%lld%lld", &A, &B, &C);

	B %= 4, C %= 32;
	for (i = 1, u = 0; u < C; i *= B, u++);

	printf("%lld", d[A % 10][(i + 3) % 4]);

	return 0;
}
