#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll arr[10000];
// Function to find power
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
 
    // Update x if it is more than or
    // equal to p
    x = x % p; 
 
    while (y > 0) {
       
        // If y is odd, multiply x 
        // with the result
        if (y & 1)
            res = (res * x) % p;
 
        // y must be even now
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll a,b,c,i,j,k,x,y,z;
    cin>>a>>b>>c;
    a=a%10;
    if (a==0)
    {
    	cout<<0<<endl;
    	return 0;
	}
    if (a==1)
    {
    	cout<<1<<endl;
    	return 0;
	}
    if (a==2)
    {
    	arr[1]=2;
    	arr[2]=4;
    	arr[3]=8;
    	arr[0]=6;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==3)
    {
    	arr[1]=3;
    	arr[2]=9;
    	arr[3]=7;
    	arr[0]=1;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==4)
    {
    	arr[1]=4;
    	arr[0]=6;
    	cout<<arr[power(b,c,2)]<<endl;
    	return 0;
	}
    if (a==5)
    {
    	cout<<5<<endl;
    	return 0;
	}
    if (a==6)
    {
    	cout<<6<<endl;
    	return 0;
	}	
    if (a==7)
    {
    	arr[1]=7;
    	arr[2]=9;
    	arr[3]=3;
    	arr[0]=1;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==8)
    {
    	arr[1]=8;
    	arr[2]=4;
    	arr[3]=2;
    	arr[0]=6;
    	cout<<arr[power(b,c,4)]<<endl;
    	return 0;
	}
    if (a==9)
    {
    	arr[1]=9;
    	arr[0]=1;
    	cout<<arr[power(b,c,2)]<<endl;
    	return 0;
	}
}
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define rng(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i)
#define per(i, b) gnr(i, 0, b)
#define all(obj) begin(obj), end(obj)
#define allr(obj) rbegin(obj), rend(obj)
#define sz(x) (int)(x).size()
#define cinv(a) rep(i, sz(a)) cin >> a[i]
#define debug(a) rep(i, sz(a)) cout << a[i] << " \n"[i == sz(a)-1]
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define pb push_back
#define eb emplace_back


typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<Pi> vp;
typedef vector<vp> vvp;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, 1, 0, -1};
const int MOD =	1e9 + 7;
const int INF = 1e9 + 9;
const ll LINF = 1e18;
const long double eps = 1e-10;
const char nl = '\n';

ll power(ll a, ll b, int mod) { return b ? power(a * a % mod, b / 2, mod) * (b % 2 ? a : 1) % mod : 1; }

ll nCk(int n, int k, int mod)
{
	ll x = 1, y = 1;
	for (int i = 1; i <= k; ++i)
	{
		x = x * (n - i + 1) % mod;
		y = y * i % mod;
	}
	return x * power(y, mod - 2, mod) % mod;
}

struct UF
{
	vi d;
	UF(int n) : d(n, -1) {}
	int root(int x)
	{
		if (d[x] < 0)
			return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (d[x] > d[y]) swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return -d[root(x)]; }
};

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(20);	
	int a, b, c; cin >> a >> b >> c;
	cout << power(a % 10, power(b, c, 4) + 4, 10) << nl;
}