#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1000000000;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    ll a, b, c;
    cin >> a >> b >> c;

    a %= 10; 
    if(a == 0) {
        cout << 0 << endl;
        return 0;
    }

    int x = a, y = 0;
    REP(i, 10){
        x *= a;
        x %= 10;
        if(a == x) {
            y = i+1;
            break;
        }
    }

    int res = modpow(b, c, y);

    int ans = 1;
    if(res == 0) res = y;
    REP(i, res){
        //cout << "U" << endl;
        ans *= a;
        ans %= 10;
    }
    
    cout << ans << endl;

    return 0;
}
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define T third
#define endl '\n'
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
const int C=1e9+7;
void yes(){
    cout<<"YES\n";
}
void no(){
    cout<<"NO\n";
}
long long binpow(long long a, long long b, long long m=C) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//Variables********************************************
bool p[200001];
//Functions********************************************
ll f(int k){
    vll v;
    for(int i=2;i<=k;i++){
        int cnt{};
        if(!p[i]) continue;
        while(k%i==0){
            k/=i;
            cnt++;
        }
        v.pb(cnt);
    }
    ll req=1;
    for(auto x:v){
        req*=(x+2)*(x+1)/2;
    }
    return req;
}

//*****************************************************
void solve(){
    int a,b,c; cin>>a>>b>>c;
    int la=a%10,lb=b%10;
    if(la==1||la==5||la==6||la==0){
        cout<<la<<endl;
        return;
    }
    if(la==9){
        if(lb%2){
            cout<<9<<endl;
        }
        else{
            cout<<1<<endl;
        }
        return;
    }
    if(la==4){
        if(lb%2){
            cout<<4<<endl;
        }
        else{
            cout<<6<<endl;
        }
        return;
    }
    int x=binpow(b,c,4);
    if(la==2){
        if(x==0){
            cout<<6<<endl;
        }
        if(x==1){
            cout<<2<<endl;
        }
        if(x==2){
            cout<<4<<endl;
        }
        if(x==3){
            cout<<8<<endl;
        }
    }
    if(la==3){
        if(x==0){
            cout<<1<<endl;
        }
        if(x==1){
            cout<<3<<endl;
        }
        if(x==2){
            cout<<9<<endl;
        }
        if(x==3){
            cout<<7<<endl;
        }
    }
    if(la==7){
        if(x==0){
            cout<<1<<endl;
        }
        if(x==1){
            cout<<7<<endl;
        }
        if(x==2){
            cout<<9<<endl;
        }
        if(x==3){
            cout<<3<<endl;
        }
    }
    if(la==8){
        if(x==0){
            cout<<6<<endl;
        }
        if(x==1){
            cout<<8<<endl;
        }
        if(x==2){
            cout<<4<<endl;
        }
        if(x==3){
            cout<<2<<endl;
        }
    }
}
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1; //cin>>t;
    while(t--){
        solve();
    }
}

