#line 1 "/workspaces/compro/lib/template.hpp"


#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i];
    if (i != size - 1)
      std::cout << " ";
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}


#line 2 "main.cpp"

long long solve(long long A, long long B, long long C) {
  vi loop;
  int now = A % 10;
  loop.push_back(now);
  while (true) {
    int next = (now * (A % 10)) % 10;
    int len = loop.size();
    if (next == loop[0])
      break;
    loop.push_back(next);
    now = next;
  }

  ll mod = loop.size();
  ll res = 1;
  while (C) {
    if (C & 1) {
      res = res * B % mod;
    }
    B = B * B % mod;
    C /= 2;
  }

  return loop[(res - 1 + mod) % mod];
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  long long A, B, C;
  std::cin >> A >> B >> C;
  auto ans = solve(A, B, C);
  std::cout << ans << std::endl;
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    if (A % 10 == 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> number;
    {
        long long x = A % 10;
        number.push_back(x);

        for (int i=0; i<10; i++) {
            x *= A;
            x %= 10;
            if (x == A % 10) break;
            number.push_back(x);
        }
    }

    vector<int> numberB;
    {
        int R = number.size();
        long long x = B % R;
        if (x == 0) {
            cout << number.at(number.size()-1) << endl;
            return 0;
        }
        numberB.push_back(x);
        for (int i=0; i<10; i++) {
            x *= B;
            x %= R;
            if (x == B % R) break;
            numberB.push_back(x);
        }
    }

    cout << number.at(
        ((int)(
            numberB.at((C-1) % numberB.size())
        )-1) % number.size()) << endl;
    
    return 0;
}