#include <iostream>

using namespace std;

int main(){
  long long a, b, c;

  cin >> a >> b >> c;

  int c_mod = c % 4;
  if(c_mod == 0)  c_mod = 4;
  int b_mod = b % 4;
  if(b_mod == 0) b_mod = 4;
  int a_down = a % 10;

  int b_res = 1;
  int a_res = 1;

  for(int i = 0; i < c_mod; i++){
    b_res *= b_mod;
  }

  b_mod = b_res % 4;
  if(b_mod == 0) b_mod = 4;

  for(int i = 0; i < b_mod; i++){
    a_res *= a_down;
  }

  int a_mod = a_res % 10;

  cout << a_mod << endl;
}
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }


//---------- (a^n)%m -----------
ll pom(ll a, ll n, int m)
{
	ll x = 1;
	for (a %= m; n; n /= 2)
		n & 1 ? x = x * a % m : 0, a = a * a % m;
	return x;
}


signed main()
{
	int A, B, C;
	cin >> A >> B >> C;

	int bc = pom(B, C, 4);

	if (bc == 0) bc = 4;

	int a = pom(A, bc, 10);

	cout << a << endl;

}

