#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
//indexed set is using "int" here--------- use ll ...
// typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define rem 1000000007
#define PI 3.141592653589793238462643383279502

ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
int phi(int n)
{
    int result = n;
    for (int i = 2; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            while (n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if (n > 1)
        result -= result / n;
    return result;
}
int main()
{
    FAST;
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll a, b, c;
    cin >> a >> b >> c;
    ll val2 = power(b, c, 4);
    ve <ll> A(2),X(2),P(2);
    P[0]=2;
    P[1]=5;
    ll R[2][2];
    rep (i,0,2)
    {
        rep (j,0,2)
        {
            R[i][j]=modInverse(P[i],P[j]);
        }
    }
    A[0]=(a%2==0?0:1);
    A[1] = (a%5==0?0:power(a, val2, 5));
    ll k=2;
    for (int i = 0; i < k; ++i)
    {
        X[i] = A[i];
        for (int j = 0; j < i; ++j)
        {
            X[i] = R[j][i] * (X[i] - X[j]);

            X[i] = X[i] % P[i];
            if (X[i] < 0)
                X[i] += P[i];
        }
    }
    ll ans=(X[0])%10+(X[1]*P[0])%10;
    cout << (ans) % 10 << "\n";
}

#include <bits/stdc++.h>
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ARTHUR_LOCAL
	#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
	#define debug(x...)
#endif

using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

ll p;

ll mod_exp(ll a, ll b)
{
	if(b==0LL) return 1LL;
 
	ll ans = mod_exp(a,ll(b/2LL));
	ans*=ans;
	ans%=p;
 
	if(b%2LL==1LL) ans*=a;
	ans%=p;
 
	return ans;
}

ll prop(ll a, ll b, ll c)
{
	p=4;
	ll expp = mod_exp(b, c);
	p=5;
	ll val = mod_exp(a, expp);
	if(val % 2LL == a % 2LL) return val;
	else return val+5;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
		// ofstream cout("arcout.txt");	
		// ifstream cin1("arcout.txt");
		// ifstream cin2("arcpyout.txt");
	#endif

	ll a,b,c;
	cin>>a>>b>>c;
	if(a%10 == 0){
		cout<<0<<endl;
		return 0;
	}
	if(a%5 == 0){
		cout<<5<<endl;
		return 0;
	}
	// EVEN CASE!!!
	a%=10LL;
	b%=4LL;
	p=4;
	ll fff=mod_exp(b,c);
	p=5;
	if(mod_exp(a,fff)%2LL == a%2LL) cout<<mod_exp(a,fff)<<endl;
	else cout<<5+mod_exp(a,fff)<<endl;
	return 0;

	// for(int i=0; i<10; i++){
	// 	for(int j=0; j<10; j++){
	// 		p=4;
	// 		cout<<i<<" "<<j<<" "<<mod_exp(i,j)<<endl;
	// 	}
	// }

	// // cout<<(10)*(4/5)*(1/2)<<endl;
	// // return 0;

	// // ll a,b,c;
	// // cin>>a>>b>>c;
	// // a%=10LL;
	// // b%=4LL;
	// // cout<<prop(a,b,c)<<endl;

	// for(int test=1; test<=10000; test++){
	// 	ll a,b,c;
	// 	// cin>>a>>b>>c;
	// 	a=randint(1000000000);
	// 	b=randint(1000000000);
	// 	c=randint(1000000000);
	// 	a%=10LL;
	// 	b%=4LL;
	// 	if(prop(a,b,c)<0LL || prop(a,b,c)>9) cout<<a<<" "<<b<<" "<<c<<endl;
	// }
}