#pragma GCC optimize("Ofast")
#pragma loop_opt(on)

#include<bits/stdc++.h>

#define Rushia_mywife ios::sync_with_stdio(0);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define FL cout.flush()
#define all(x) (x).begin(),(x).end()
#define mem(x,i) memset((x),(i),sizeof((x)))

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<long long,long long>;
using ld = long double;

mt19937 mtrd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1000000007;
const int mod2 = 998244353;
const ld PI = acos(-1);

#define Bint __int128
#define int long long
int qpow(int x,int powcnt,int tomod){
	int res = 1;
	for(;powcnt;powcnt>>=1,x=(x*x)%tomod)
		if(1&powcnt)res = (res*x)%tomod;
	return (res%tomod);
}
int inv(int x){ return qpow(x,mod-2,mod); }
// --------------------------------------**

vector<int>cyc[10];
bool vis[10];

void solve(){
	for(int i=0;i<10;i++){
		mem(vis,0);
		cyc[i].pb(i);
		vis[i] = 1;
		int x = i*i%10;
		while(!vis[x]){
			vis[x] = 1;
			cyc[i].pb(x);
			x = x*i%10;
		}
	}
	int a,b,c;
	cin >> a >> b >> c;
	int x = qpow(b,c,(int)cyc[a%10].size());
	cout << cyc[a%10][(x-1+cyc[a%10].size())%(int)cyc[a%10].size()] << '\n';
}

signed main(){
    Rushia_mywife
    int t = 1; 
    //cin >> t;
    while(t--)
        solve();
}


#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<string>
#include<vector>
#include<set>

#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;

long long int  powMod(long long int  x, long long int  k, long long int  m) {
  if (k == 0)     return 1;
  if (k % 2 == 0) return powMod(x*x % m, k/2, m);
  else            return x*powMod(x, k-1, m) % m;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//φ関数

long long int  euler_phi(long long int n) {
  long long int ret = n;
  for(long long int  i = 2; i * i <= n; i++) {
    if(n % i == 0) {
      ret -= ret / i;
      while(n % i == 0) n /= i;
    }
  }
  if(n > 1) ret -= ret / n;
  return ret;
}

int main(void){

    long long int a,b,c;

    cin >> a >> b >> c;
    //bの偶奇

    int moto = a%10;
    if(moto==0||moto == 1){
        cout << moto << endl;
        return 0;
    }
    if(moto==4){
        int jyou = powMod(b,c,2);
        if(jyou ==0){
            cout << moto*moto%10 << endl;
            return 0;
        }
        cout << powMod(a%10,jyou,10);
    }
    if(moto == 5){
        cout << moto<<endl;
        return 0;
    }
    if(moto == 6){
        cout << moto<<endl;
        return 0;
    }
    if(moto==7||moto==8||moto==2||moto==3){
        int jyou = powMod(b,c,4);
        if(jyou ==0){
            cout << moto*moto*moto*moto%10 << endl;
            return 0;
        }
        cout << powMod(a%10,jyou,10);
        return 0;
    }
   
    if(moto==9){
        if(b%2==0){
            cout << 1 << endl;
        }
        else{
            cout << 9<<endl;
        }
    }

    

    return 0;
}