#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const int N = 1e5 + 10;
const ll mod = 1e9 + 7;

ll a, b, c;

ll fast_pow(ll p, ll q, ll MOD) {
    ll ans = 1;
    while (q) {
        if (q & 1) {
            ans = ans * p % MOD;
        }
        p = p * p % MOD;
        q >>= 1;
    }
    return ans;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.txt", "r", stdin);
#endif
    scanf("%lld%lld%lld", &a, &b, &c);
    ll cur = a % 10, w;
    if (cur == 0) {
        printf("0\n");
    } else if (cur == 1) {
        printf("1\n");
    } else if (cur == 2) {
        w = fast_pow(b, c, 4);
        if (!w)printf("6\n");
        else if (w == 1)printf("2\n");
        else if (w == 2)printf("4\n");
        else if (w == 3)printf("8\n");
    } else if (cur == 3) {
        w = fast_pow(b, c, 4);
        if (!w)printf("1\n");
        else if (w == 1)printf("3\n");
        else if (w == 2)printf("9\n");
        else if (w == 3)printf("7\n");
    } else if (cur == 4) {
        w = fast_pow(b, c, 2);
        if (!w)printf("6\n");
        else if (w == 1)printf("4\n");
    } else if (cur == 5) {
        printf("5\n");
    } else if (cur == 6) {
        printf("6\n");
    } else if (cur == 7) {
        w = fast_pow(b, c, 4);
        if (!w)printf("1\n");
        else if (w == 1)printf("7\n");
        else if (w == 2)printf("9\n");
        else if (w == 3)printf("3\n");
    } else if (cur == 8) {
        w = fast_pow(b, c, 4);
        if (!w)printf("6\n");
        else if (w == 1)printf("8\n");
        else if (w == 2)printf("4\n");
        else if (w == 3)printf("2\n");
    } else if (cur == 9) {
        w = fast_pow(b, c, 2);
        if (!w)printf("1\n");
        else if (w == 1)printf("9\n");
    }
    return 0;
}
#include <bits/stdc++.h>
using namespace std;
int64_t power(int64_t base, int64_t exponent, int64_t mod) {
  base %= mod;
  int64_t result = base ? 1 : 0;
  while (exponent) {
    if (exponent & 1) {
      result *= base;
      result %= mod;
    }
    base *= base;
    base %= mod;
    exponent >>= 1;
  }
  return result;
}
int main() {
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int64_t a, b, c;
  cin >> a >> b >> c;
  cout << power(a, power(b, c, 2520), 10) << "\n";
  return 0;
}
