#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}
ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B, long long C)
{
    if (A % 10 == 0)
    {
        cout << 0 << endl;
        return;
    }
    else if (A % 10 == 1)
    {
        cout << 1 << endl;
        return;
    }
    else if (A % 10 == 2)
    {
        ll ans[4] = {6, 2, 4, 8};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 3)
    {
        ll ans[4] = {1, 3, 9, 7};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 4)
    {
        ll ans[2] = {6, 4};
        // 4,6,4,6,4,6....
        MOD = 2;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 5)
    {
        cout << 5 << endl;
        return;
    }
    else if (A % 10 == 6)
    {
        cout << 6 << endl;
        return;
    }
    else if (A % 10 == 7)
    {
        ll ans[4] = {1, 7, 9, 3};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 8)
    {
        ll ans[4] = {6, 8, 4, 2};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
        // 8,4,2,6,8....
    }
    else if (A % 10 == 9)
    {
        ll ans[2] = {1, 9};
        MOD = 2;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
        // 9,1,9,1...
    }
}

int main()
{

    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
	ll a, b, c;
    cin >> a >> b >> c;

    a %= 10;
    b %= 4;

    ll x;
    if(b==0) x=4;
    else if(b==1) x=1;
    else if(b==2){
        if(c>1) x=4;
        else x=2;
    }else{
        if(c%2==0) x=1;
        else x=3;
    }

    ll ans=powl(a, x);
    cout << ans%10 << endl;

	
	return 0;
}
