#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll M = 998244353;

long long myMod(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a%mod;
		a = a * a%mod;
		n >>= 1;
	}
	return res;
}


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << myMod(a, myMod(b, c, 4) + 4, 10);
}
#include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 1e9 + 7;
const int64_t MOD2 = 998244353;
const int INF = 1e9;
const long long inf = 1LL<<60;

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  a %= 10;
  long long num = a;
  vector<int> A(10, 0);
  vector<int> loopA;
  A.at(num) = 1;
  loopA.push_back(num);
  while (1) {
    num *= a;
    num %= 10;
    if (A.at(num) == 1) {
      break;
    } else {
      A.at(num) = 1;
      loopA.push_back(num);
    }
  }
  int loopasize = (int)loopA.size();
  num = b;
  num %= loopasize;
  vector<int> B(loopasize, 0);
  vector<int> loopB;
  B.at(num) = 1;
  loopB.push_back(num);
  while (1) {
    num *= b;
    num %= loopasize;
    if (B.at(num) == 1) {
      break;
    } else {
      B.at(num) = 1;
      loopB.push_back(num);
    }
  }
  long long k;
  if ((loopB.back() == 0) && ((int)loopB.size() <= c)) {
    k = 0;
  } else {
    k = loopB.at((c+(int)loopB.size()-1)%((int)loopB.size()));
  }
  long long res;
  if (k%loopasize == 0) {
    res = loopA.back();
  } else {
    res = loopA.at((k-1)%loopasize);
  }
  cout << res << endl;
}
