#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
ll mod;
ll ksm(ll x,ll y)
{
	if(y==0)
	{
		return 1;
	}
	ll ret=ksm(x,y>>1);
	ret=(ret*ret)%mod;
	if(y&1)
	{
		ret=(ret*x)%mod;
	}
	return ret;
}
ll a,b,c,vis[15];
vector<ll> md;
int main(){
	ll i,x,st;
	cin>>a>>b>>c;
	x=1;
	memset(vis,-1,sizeof(vis));
	for(i=0;i<100;i++)
	{
		md.push_back(x);
		vis[x]=i;
		x*=a;
		x%=10;
		if(vis[x]!=-1)
		{
			st=vis[x];
			break;
		}
	}
	mod=md.size()-st;
	x=(ksm(b,c)-st+100*mod)%mod+st;
	mod=10;
	cout<<ksm(a,x)<<endl;
	return 0;
}
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}

int main(){

	ll A,B,C;

	scanf("%lld %lld %lld",&A,&B,&C);

	ll ch = A%10;

	if(ch == 1 || ch == 6 || ch == 5){

		printf("%lld\n",ch);
		return 0;
	}

	ll mult = mod_pow(B,C,4);
	ll ans = mod_pow(ch,mult+4,10);

	printf("%lld\n",ans);

	return 0;
}

