#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cout << #a << ": " << a << endl;
#define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl;
#define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; }
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }

template <ll Mod> class modint;
template <class T> T permutation(T n, T k, T mod) { T f(1); for (T i=0; i<k; ++i, --n) f = f*n % mod; return f; }
template <class T> T factorial(T n, T mod) { return permutation<T>(n,n,mod); }
template <class T> T powmod(T e, T p, T mod) { if(p == -1) p=mod-2; T a=1; while(p>0){ if(p&1){ a=a*e%mod; } e=e*e%mod; p>>=1; } return a; }
template <class M> M powmod(M e, ll p) { if(p == -1) return e.inv(); return e.pow(p); }
template <class T> T binomial(T n, T k, T mod) { return permutation<T>(n,k,mod) * powmod<T>(factorial<T>(k,mod), -1, mod) % mod; }

template <class T> T permutation(ll n, ll k) { T f(1); for (ll i=0; i<k; ++i, --n) f *= n; return f; }
template <class T> T factorial(ll n) { return permutation<T>(n,n); }
template <class T> T binomial(ll n, ll k) { k=min(n,n-k); ll t=1; for (ll i=0; i<k; ++i) t*=n-i,t/=i+1; return t; }

int main() {
    fastio;
    ll ans{};
    ll a,b,c;
    cin >> a >> b >> c;
    ll t = powmod(b,c,4LL);
    a %= 10;
    if (a == 0 || a == 1 || a == 5 || a == 6) ans = a;
    else if (a == 4 || a == 9) {
        t = (t+1)%4 + 1;
        ans = powmod(a,t,10LL);
    } else {
        t = (t+3)%4 + 1;
        ans = powmod(a,t,10LL);
    }
    cout << ans << endl;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<random>
#include<ctime>
#include<cstring>
#include<map>
#include<queue>
#define mp make_pair
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-') f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return f==1?x:~x+1;
}
//const int mod=9;
int qpow(int x,int k,int mod){
	x%=mod;
	int res=1;
	while(k){
		if(k&1) res=res*x%mod;
		k>>=1;x=x*x%mod;
	}
	return res;
}
int main(){
	int a=read(),b=read(),c=read();
//	printf("%d\n",qpow(b,c));
	printf("%d\n",qpow(a,qpow(b,c,8)==0?8:qpow(b,c,8),10));
}