// Problem: B - A^B^C
// Contest: AtCoder - AtCoder Regular Contest 113
// URL: https://atcoder.jp/contests/arc113/tasks/arc113_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod=1000000007;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize


#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)

int get_val(int a,int b,int c)
{
	int res=1;
	if(a==0)
	return 0;
	if(a==1)
	return 1;
	while(b)
	{
		if(b&1)
		{
			res=((res%c)*(a%c))%c;
		}
		b/=2;
		a=((a%c)*(a%c))%c;
	}
	return res%c;
}
void solve()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<get_val(a%10,get_val(b,c,4)+4,10)%10<<endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
//    cin>>t;
    while(t--)
        solve();
}
#include<iostream>
using namespace std;
long long int MOD = 10;
long long int POW(long long int n,long long int k){
	long long int r;
	if(k==0)return 1;
	r=POW(n,k/2)%MOD;
	r=(r*r)%MOD;
	if(k%2)r=(n*r)%MOD;
	return r;
}
int main(){
	long long int A,B,C,bc;
	long long int mod[10]={1,1,4,4,2,1,1,4,4,2};
	cin>>A>>B>>C;A%=10;
	MOD = mod[A];
	bc=POW(B,C)+MOD;
	MOD = 10;
	cout<<POW(A,bc);
	return 0;
}