#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#pragma region DEBUG
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef
tree<
  pair<int,int>,
  null_type,
  less<pair<int,int>>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
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...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
vector <lli> fact(MAX,1);
vector <lli> invfact(MAX,1);
lli binpow(lli a, lli b, lli m){
    //a %= m;
    lli res = 1;
    while(b > 0){
        if(b&1)
            res = a*res%m;
        b >>=1;
        a = a*a%m;
    }
    return res;
}
void solve(){
   lli a,b,c;
   cin>>a>>b>>c;
   lli X = binpow(b,c,4);
   //debug(X);
   if(X == 0)
        X = 4;
   lli ans = binpow(a%10, X, MOD);
   cout<<(ans%10)<<endl;
}
int main(){
    /* freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   /*  for(lli i = 1; i<MAX-5; i++){
        fact[i] = i*fact[i-1]%MOD;
        invfact[i] = binpow(fact[i],MOD-2);
    } */
    lli t;
    t = 1;
    //cin>>t;
    while(t--)
        solve();
}
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int a, B, c;

inline int fpow(int x, int b, int m) {
    int res = 1;
    while (b) {
        if (b & 1) res = 1ll * res * x % m;
        x = 1ll * x * x % m;
        b >>= 1;
    }
    return res;
}

int main() {
    cin >> a >> B >> c;
    cout << fpow(a, 4 + fpow(B, c, 4), 10);
}