#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long

ull large(ull b, ull c, ull mod) {
    ull ans = 1;
    for(ull i=0; i<c; i++) {
        ans = (ans*b)%mod;
    }
    return ans;
}
int main() {
    ull a,b,c;
    cin>>a>>b>>c;
    ull bc;
    if(b*c>10) {
        bc = large(b,c,4);
        if(bc==0) bc = 4;
    }
    else {
        bc = pow(b,c);
    }
    // cout<<bc<<endl;
    ull ans = large(a,bc,10);
    cout<<ans<<endl;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

ll rui(ll a,ll b,ll c){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%c;
        a=a*a%c;
        b/=2;
    }
    return ans;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll A,B,C;cin>>A>>B>>C;
    if(B==1){
        cout<<rui(A,C,10)<<endl;
        return 0;
        
    }
    A%=10;
    vector<int> wh(10,-1);
    ll now=1;
    int s,t=0;
    for(;;t++){
        if(wh[now]!=-1){
            s=wh[now];
            break;
        }
        wh[now]=t;
        now*=A;
        now%=10;
    }
    
    now=1;
    for(int i=0;i<C;i++){
        now*=B;
        if(now>=s) break;
    }
    
    if(now<s){
        for(int i=0;i<10;i++){
            if(wh[i]==now){
                cout<<i<<endl;
                return 0;
            }
        }
    }
    
    B%=(t-s);
    
    ll X=rui(B,C,(t-s));
    
    for(int i=0;i<10;i++){
        if(wh[i]>=s&&wh[i]%(t-s)==X){
            cout<<i<<endl;
            return 0;
        }
    }
    
}
