#include <bits/stdc++.h>

const int phi10 = 4;// 1 3 7 9
int a, b, c;

int qpow(int a, int b, int p){
	int res = 1;
	a %= p;
	while(b){
		if(b & 1) res = res * a % p;
		a = a * a % p, b >>= 1;
	}
	return res;
}

int main(){
	std::scanf("%d%d%d", &a, &b, &c);
	std::printf("%d\n", qpow(a, qpow(b, c, phi10) + phi10, 10));
}
#include <cmath>
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define all(x) x.begin(),x.end()

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

void solve()
{
  int a,b,c;
  map<int,vector<int>> mp;
  mp[2] = {6,2,4,8};
  mp[3] = {1,3,9,7};
  mp[7] = {1,7,9,3};
  mp[8] = {6,8,4,2};
  cin >> a >> b >> c;
  if(a%10==0 || a%10==5 || a%10==6 || a%10==1){
    cout << a%10 << endl;
    return;
  }
  else if(a%10==4){
    if(b%2==0) cout << 6 << endl;
    else cout << 4 << endl;
  }
  else if(a%10==9){
    if(b%2==0) cout << 1 << endl;
    else cout << 9 << endl;
    return;
  }
  else{
    int r = b%4;
    if(r==0) cout << mp[a%10].at(0) << endl;
    else if(r==1) cout << mp[a%10].at(1) << endl;
    else if(r==2){
        if(c>=2) cout << mp[a%10].at(0) << endl;
        else cout << mp[a%10].at(2) << endl;
    }
    else if(r==3){
        if(c%2==0) cout << mp[a%10].at(1) << endl;
        else cout << mp[a%10].at(3) << endl;
    }
    return;
  }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--) solve();
    return 0;
}

