#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
// 繰り返し自乗法(x^nをmで割った余り) O(logn)
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;
}
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  
  ll d = modpow(b, c, 4);
  if (d == 0) d += 4;
  
  cout << modpow(a, d, 10) << '\n';
}
#include <bits/stdc++.h>
using namespace std;

const long long inf = (long long)1e9 * (long long)1e9;

map<int, int>mods;

long long calculateMod(long long b, long long c, int mod) {
  // oblicz reszte z dzielenia b^c przez mod, mod <= 5
  if (c == 1) return b%mod;
  if (c == 0) return 1;
  b %= mod;
  long long half = calculateMod(b, c/2, mod);
  long long rest = 1;
  if (c % 2 == 1) rest = b;
  return (((half * half) % mod) * rest) % mod;
}

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  a %= 10;
  if (a == 0 || a == 1 || a == 5 || a == 6) {
    printf("%d\n", a);
    return 0;
  }

  mods[2] = 4;
  mods[3] = 4;
  mods[4] = 2;
  mods[7] = 4;
  mods[8] = 4;
  mods[9] = 2;

  int mod = calculateMod(b, c, mods[a]);
  // printf("%d\n", calculateMod(2, 20, 100000000));
  // return 0;
  // printf("%d\n", mod);

  if (a == 2) {
    int mods[] = {6, 2, 4, 8};
    printf("%d\n", mods[mod]);
  }
  if (a == 3) {
    int mods[] = {1, 3, 9, 7};
    printf("%d\n", mods[mod]);
  }
  if (a == 4) {
    int mods[] = {6, 4};
    printf("%d\n", mods[mod]);
  }
  if (a == 7) {
    int mods[] = {1, 7, 9, 3};
    printf("%d\n", mods[mod]);
  }
  if (a == 8) {
    int mods[] = {6, 8, 4, 2};
    printf("%d\n", mods[mod]);
  }
  if (a == 9) {
    int mods[] = {1, 9};
    printf("%d\n", mods[mod]);
  }

  return 0;
}