#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main(){
    long a,b,c;
    cin >> a >> b >> c;
    a %= 10;
    b %= 4;
    long iIndex = 0;
    if(b == 0){
        iIndex = 4;
    } else if (b == 1){
        iIndex = 1;
    } else if (b == 2){
        iIndex = (c > 1) ? 4 : 2;
    } else {
        iIndex = (c % 2 == 0) ? 1 : 3;
    }
  
    long nAns = 1;
    for(long i = 0; i < iIndex; i++){
        nAns *= a;
        nAns %= 10;
    }
  
    cout << nAns << endl;
    
    return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i=a, _n=b; i<=_n; ++i)
#define FORD(i, a, b) for(int i=a, _n=b; i>=_n; --i)
using namespace std;

int mod = 0, m, p, k, e[20], vis[20];

int pw(int b, int c) {
    if (c == 1) {
        if (b > k) b %= m, mod = 1;
        return b;
    }

    int tmp = pw(b, c >> 1);
    tmp = tmp * tmp * (c&1 ? b : 1);
    if (mod || tmp > k) tmp %= m, mod = 1;
    return tmp;
}
int main()
{
    ios::sync_with_stdio();
    cin.tie(0); cout.tie(0);
    ///freopen("a.inp","r",stdin);

    int a, b, c;
    cin >> a >> b >> c;
    a %= 10;
    memset(vis, -1, sizeof(vis));
    e[0] = 1; vis[1] = 0;
    k = 0; while (-1 == vis[(e[k] * a) % 10]) {
        e[k+1] = (e[k] * a) % 10;
        k += 1; vis[e[k]] = k;
    }

    p = vis[(e[k] * a) % 10];
    m = k - p + 1;

    int tmp = pw(b, c);
    if (mod) while (tmp < p) tmp += m;

    cout << e[tmp];
}
