#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 1600008
#define mod 998244353
#define f first
#define s second
ll arr[sz+10],brr[sz+10];
ll num=1;
char c[sz];
std::vector<ll> v[34];
long long binpow(long long a, long long b,long long mod1) {
    a %= mod1;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod1;
        a = a * a % mod1;
        b >>= 1;
    }
    return res;
}
int main()
{
  int t=1;
  //scanf("%d",&t);
  for(int cs=1;cs<=t;cs++)
  {
      ll a,b,c;
      scanf("%lld %lld %lld",&a,&b,&c);
      a%=10;
      ll n=a;
      arr[n]++;
      ll val=0;
      for(int i=2;;i++)
      {
       n=(n*a)%10;
       if(arr[n])
       {
        val=i-1;
        break;
       }
      }
      ll a1=binpow(b,c,val);
      if(a1==0)
      	a1=val;
      	n=a;
      	for(int i=2;i<=a1;i++)
      		n=(n*a)%10;
        a=n;
        printf("%lld\n",a);
  }
  return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
typedef long long ll;
const double pi = acos(-1.0);
#define debug puts("*****************")
#define memset(a,b) memset(a,b,sizeof(a))
const int mod = (1 ? 1000000007 : 998244353);
const int inf = (1 ? 0x3f3f3f3f : 0x7fffffff);
const int dx[] = { -1,0,1,0 }, dy[] = { 0,1,0,-1 };
const ll INF = (1 ? 0x3f3f3f3f3f3f3f3f : 0x7fffffffffffffff);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll poww(ll a, ll b,ll mod) { ll s = 1; while (b) { if (b & 1)s = (s * a) % mod; a = (a * a) % mod; b >>= 1; }return s % mod; }
/*----------------------------------------------------------------------------------------------------------------------*/

const int N = 1e5 + 11;
ll n,m;

void solve()
{
	ll a,b,c;
	cin>>a>>b>>c;
	b=poww(b,c,4);
	a%=10;
	if(a==1||a==5||a==6||a==0)
	{
		cout<<a<<endl;
		return;
	}
	if(a==4&&b%2==1)cout<<4<<endl;
	else if(a==4&&b%2==0)cout<<6<<endl;
	else if(a==9&&b%2==1)cout<<9<<endl;
	else if(a==9&&b%2==0)cout<<1<<endl;	
	else
	{
		int z[4];
		if(a==2){z[0]=6;z[1]=2;z[2]=4;z[3]=8;}
		if(a==3){z[0]=1;z[1]=3;z[2]=9;z[3]=7;}
		if(a==7){z[0]=1;z[1]=7;z[2]=9;z[3]=3;}
		if(a==8){z[0]=6;z[1]=8;z[2]=4;z[3]=2;}
		cout<<z[b]<<endl;
	}
}


/*----------------------------------------------------------------------------------------------------------------------*/
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    ll T = 1;
    //cin >> T;
    while (T--)solve();
    return 0;
}
