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

ll pow_m(ll a ,ll b,ll m){
  ll ans = 1;
  while(b){
    if(b&1) ans = ans * a %m;
    a = a *a % m;
    b >>= 1;
  }
  return ans;
}

int main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
   ll a,b,c;
   cin >> a >> b >> c;
   
   ll k = pow_m(b,c,4) ? pow_m(b,c,4) : 4;
   cout <<  pow_m(a,k,10);
   return 0;
}

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

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vpll = vector<pair<ll, ll>>;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1<<30;
const ll INF = 1ll<<60;
const ll mod = 1000000007;
//const ll mod = 998244353;
//const ll dx[4] = {1, 0, -1, 0};
//const ll dy[4] = {0, 1, 0, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class T> void disp1(vector<T> &array, bool blank=1) {
    rep(i, array.size()) cout << ((i&&blank) ? " " : "") << array[i];
    cout << endl;
    //cout << " ";
}
template<class T> void disp2(vector<vector<T>> &array, bool blank=1) {
    rep(i, array.size()) disp1(array[i], blank);
}

ll rem(ll a, ll b) { return (a % b + b) % b; }      // 余りを0~b-1に丸める
// 小数の入力が文字で与えられたとき、10^n倍したものを返す
ll x10(string str_f, ll n) {
    if (str_f[0] == '-') return -x10(str_f.substr(1), n);
    ll times = 1; rep(i,n) times *= 10;     // times = 10^n
    int id = -1; rep(i,str_f.size()) if (str_f[i] == '.') id = i;
    if (id == -1) { return stoll(str_f)*times; }
    string str_int = str_f.substr(0, id), str_dec = str_f.substr(id+1);
    while (str_dec.size() < n) str_dec += '0';
    return stoll(str_int)*times + stoll(str_dec);
}
// A^N (mod)
ll modpow(ll A, ll N, ll mod) {
    ll RES = 1;
    while (N) {
        if (N & 1) RES = RES * A % mod;
        A = A * A % mod;
        N >>= 1;
    }
    return RES;
}

//using mint = modint1000000007;

int main() {
    ll a, b, c; cin >> a >> b >> c;
    a %= 10;
    ll p = a;
    vll seen(10, 0), aa;
    while (1) {
        if (seen[a]) break;
        aa.pb(a);
        seen[a] = 1;
        a = a*p%10;
    }
    ll ans = aa[(modpow(b, c, sz(aa))+sz(aa)-1)%sz(aa)];
    cout << ans << endl;
    return 0;
}