#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e6;
ll a,b,c;
ll binpow(ll a,ll b){
    ll res = 1;
    while(b){
        if(b & 1){
            res *= a;
            res %= 4;
        }
        a *= a;
        a %= 4;
        b >>= 1;
    }
    return res;
}
int main(){
    ios::sync_with_stdio(0);

    cin >> a >> b >> c;

    int x = binpow(b,c);
    //cout << x << endl;
    ll d = 1;
    if(x == 0) x = 4;
    while(x--){
        d*=a;
        d%=10;
    }


    cout << d << endl;
}

# include <bits/stdc++.h>
using namespace std;

#define ll          long long
#define int        ll
#define pb          push_back
#define ppb         pop_back
#define eb          emplace_back
#define endl		'\n'
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define vi          vector<int>
#define vii         vector<pair<int, int> >
#define mp          make_pair
#define mem1(a)     memset((a),-1,sizeof(a))
#define mem0(a)     memset((a),0,sizeof(a))
#define memf(a)     memset((a),false,sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (a)*((b)/gcd((a),(b)))
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mi          map<int,int>
#define sz(x)       (ll)(x).size()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define pii         pair<int,int>

// Returns pow(base,exponent)%MOD in log(exponent) using binary exponentiation

int powermodp(long long base, long long exponent, long long mod) {
	long long ans = 1;
	while (exponent != 0)
	{
		if (exponent & 1)
			ans = (1LL * ans * base) % mod;
		base = (1LL * base * base) % mod;
		exponent >>= 1;
	}
	return ans % mod;
}

int solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	int r = powermodp(b, c, 4);
	r+=4;
	int e = powermodp(a, r, 10);
	cout << e;

	return 0;
}
signed main()
{
	FAST
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int t = 1;
	// cin>>t;
	while (t)
	{
		solve();
		t--;
	}
	return 0;
}