#include <iostream>

using namespace std;

int a, b, c, p, ans = 1;

int ksm(int b, int c) {//快速幂求b^c
  int ans = 1;
  for (int i = b; c; i = 1ll * i * i % p, c >>= 1) {
    if (c & 1) {
      ans = 1ll * ans * i % p;
    }
  }
  return ans;
}

int main() {
  cin >> a >> b >> c;
  a = a % 10;
  if (a == 0 || a == 1 || a == 5 || a == 6){
    cout << a << endl;
    return 0;
  }
  if (a == 2 || a == 3 || a == 7 || a == 8) {
    p = 4;
  }
  else {
    p = 2;
  }
  int t = ksm(b, c);
  if (!t) {
    t = p;
  }
  while (t--) {
    ans = ans * a % 10;
  }
  cout << ans << endl;
  return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll A,B,C;
ll modpow(ll a, ll n,ll mo) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	A%=10;
	/*
	if(A<=1) {
		cout<<A<<endl;
		return;
	}
	vector<ll> V;
	V.push_back(A);
	while(1) {
		V.push_back(V.back()*V[0]%10);
		if(V[0]==V.back()) {
			V.pop_back();
			break;
		}
	}
	*/
	x=modpow(B,C,12);
	cout<<modpow(A,x+12,10)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
