#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define f(n) for(int i=0;i<n;i++)
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

int arr[]={1,1,4,4,2,1,1,4,4,2};

ll pow(ll a,ll b,ll m)
{
    ll res=1;

    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
    }

    return res;
}

void solve()
{
    int n=3;
    //cin>>n;

    ll A[n];

    f(n)cin>>A[i];

    for(int i=n-2;i>0;i--)
    {
        ll x=A[i]%10,y=A[i+1];

        A[i]=pow(A[i],A[i+1],arr[A[0]%10])+arr[A[0]%10];
    }

    A[0]=pow(A[0],A[1],10)%10;
    cout<<(A[0]%10);
}

int main()
{
    FastIO;

    int t=1;
	//cin>>t;

	for(int i=1;i<=t;i++)
    {
        solve();
        if(i!=t)cout<<endl;
    }
	return 0;
}

#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll power(ll x, ll y, ll m)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
}

int main(void)
{
    ll a, b, c;
    cin >> a >> b >> c;

    vector<ll> m;
    ll tmp = a % 10;
    m.push_back(tmp);

    for (int i = 0; i < 100; i++)
    {
        tmp *= a;
        tmp %= 10;

        if (tmp == a % 10)
        {
            break;
        }

        m.push_back(tmp);
    }

    cout << m[(power(b, c, m.size()) - 1 + m.size()) % m.size()] << endl;
}