#include <cstdio>

using u32 = unsigned int;
using u64 = unsigned long long int;


/*
A^{B^C} mod 10

0
1 1
2 4 8 6 2
3 9 7 1 3
4 6 4
5 5
6 6
7 9 3 1 7
8 4 2 6 8
9 1 9
*/

u32 modpow(u32 a, u32 n, u32 mod){
  u32 r = 1;
  for(; n; n>>=1){
    if(n&1) r = (u64) r * a % mod;
    a = (u64) a * a % mod;
  }
  return r;
}


int main(){
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if(a % 10 == 0){
    puts("0");
  }
  else if(a % 10 == 1 || a % 10 == 5 || a % 10 == 6){
    printf("%d\n", a % 10);
  }
  else if(a % 10 == 2 || a % 10 == 3 || a % 10 == 7 || a % 10 == 8) {
    u32 x = modpow(b, c, 4);
    printf("%u\n", modpow(a%10, x+4, 10));
  }
  else if(a % 10 == 4 || a % 10 == 9) {
    u32 x = modpow(b, c, 2);
    printf("%u\n", modpow(a%10, x+2, 10));
  }

  return 0;
}

// 2021-02-21 21:21:33
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

// clang-format on
ll pw10(ll n, ll m, ll mod) {
  ll res = 1;
  ll b = n;
  while (m > 0) {
    if (m & 1) res *= b;
    b *= b;
    res %= mod;
    b %= mod;
    m >>= 1;
  }
  return res % mod;
}
void answer() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a % 10 == 0) {
    cout << 0 << '\n';
    return;
  }
  if (a % 10 == 1) {
    cout << 1 << '\n';
    return;
  }
  int mod;
  {
    vector<int> id(10, -1);
    ll n = a % 10;
    int cur = 0;
    while (id[n] == -1) {
      id[n] = cur++;
      n *= a;
      n %= 10;
    }
    mod = cur;
  }
  ll d = pw10(b, c, mod);
  d--;
  d += mod;
  d %= mod;
  ll ans = a % 10;
  rep(i, d) {
    ans *= a;
    ans %= 10;
  }
  cout << ans << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}