#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <utility>
#include <queue>
#include <map>
#include <assert.h>
#include <stack>
#include <string>
#include <ctime>
#include <chrono>
#include <random>
#define int long long int
using namespace std;

int exp(int x, int n, int p)		//x^n%p in log(n)
{	
	if (n==0)
	{
		return 1;
	}
	else if (n==1)
	{
		return x%p;
	}
	else
	{
		if (n%2==0)
		{
			return (exp((x*x)%p, n/2, p));
		}
		else
		{
			return (x*exp((x*x)%p, n/2, p))%p;
		}
	}
}

int get(int d, int idx)
{
	int res=1;
	while (idx--)
	{
		res*=d;
		res%=10;
	}
	return res;
}

int period(int d)
{
	int res=d*d;
	int p=1;
	while (res%10!=d)
	{
		p++;
		res*=d;		
	}
	return p;
}

void solve()
{
	int a, b, c;
	cin>>a>>b>>c;
	cout<<get(a%10, exp(b, c, period(a%10)) ? exp(b, c, period(a % 10) ) : period(a%10))<<"\n";
	return;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	
	
	int t;	
	//cin >> t;
	t=1;
	
	while (t--)
	{
		solve();
	}
	return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll a, b, c;
    cin >> a >> b >> c;
    
    if(a % 10 <= 1) {
        cout << a % 10 << endl;
        return 0;
    }

    // next[i][j]: 1の位が i の数に a を 2^j 回かけると 1 の位が next[i][j] になる
    vector<vector<ll>> next(10, vector<ll>(60, -1));
    // next2[i][j]: 1の位が i になるものを 2^j 回かけると 1 の位が next2[i][j] になる
    vector<vector<ll>> next2(10, vector<ll>(60, -1));
    for(int i=0;i<10;++i) {
        next[i][0] = (i * a) % 10;
        next2[i][0] = i;
    }
    for(int j=0;j<59;++j) {
        for(int i=0;i<10;++i) {
            if(next[i][j] != -1) next[i][j+1] = next[next[i][j]][j];
            if(next2[i][j] != -1) next2[i][j+1] = (next2[i][j] * next2[i][j]) % 10;
        }
    }

    // next3[i][j]: 1の位が i になるものを b 乗するのを 2^j 回繰り返す
    vector<vector<ll>> next3(10, vector<ll>(60, -1));
    for(int i=0;i<10;++i) {
        next3[i][0] = 1;
        for(int j=59;j>=0;--j) {
            if(b & (1LL << j)) next3[i][0] = (next3[i][0] * next2[i][j]) % 10;
        }
    }
    for(int j=0;j<59;++j) {
        for(int i=0;i<10;++i) {
            if(next3[i][j] != -1) next3[i][j+1] = next3[next3[i][j]][j];
            // if(j <= 3) cerr << i << ", " << j << ": " << next3[i][j] << endl;
        }
    }

    // a に ^b を c 回適用
    int ans = a % 10;
    for(int j=59;j>=0;--j) {
        if (c & (1LL << j)) {
            ans = next3[ans][j];
        }
    }

    cout << ans << endl;

}
