#include<bits/stdc++.h>
using namespace std;

int main(){
  long long int A,B,C;
  cin >> A >> B >> C;
  A %= 10;
  if(A == 0) cout << 0 << endl;
  if(A == 1) cout << 1 << endl;
  if(A == 5) cout << 5 << endl;
  if(A == 6) cout << 6 << endl;
  if(A == 2){
    B %= 4;
    if(B == 1) cout << 2 << endl;
    if(B == 2){
      C %= 4;
      if(C == 1) cout << 4 << endl;
      if(C == 2) cout << 6 << endl;
      if(C == 3) cout << 6 << endl;
      if(C == 0) cout << 6 << endl;
    }
    if(B == 3){
      C %= 4;
      if(C == 1) cout << 8 << endl;
      if(C == 2) cout << 2 << endl;
      if(C == 3) cout << 8 << endl;
      if(C == 0) cout << 2 << endl;
    }
    if(B == 0) cout << 6 << endl;
  }
  if(A == 3){
    B %= 4;
    if(B == 1) cout << 3 << endl;
    if(B == 2){
      C %= 4;
      if(C == 1) cout << 9 << endl;
      if(C == 2) cout << 1 << endl;
      if(C == 3) cout << 1 << endl;
      if(C == 4) cout << 1 << endl;
    }
    if(B == 3){
      C %= 4;
      if(C == 1) cout << 7 << endl;
      if(C == 2) cout << 3 << endl;
      if(C == 3) cout << 7 << endl;
      if(C == 0) cout << 3 << endl;
    }
    if(B == 0) cout << 1 << endl;
  }
  if(A == 4){
    B %= 2;
    if(B == 1) cout << 4 << endl;
    if(B == 0) cout << 6 << endl;
  }
  if(A == 7){
    B %= 4;
    if(B == 1) cout << 7 << endl;
    if(B == 2){
      C %= 4;
      if(C == 1) cout << 9 << endl;
      if(C == 2) cout << 1 << endl;
      if(C == 3) cout << 1 << endl;
      if(C == 0) cout << 1 << endl;
    }
    if(B == 3){
      C %= 4;
      if(C == 1) cout << 3 << endl;
      if(C == 2) cout << 7 << endl;
      if(C == 3) cout << 3 << endl;
      if(C == 0) cout << 7 << endl;
    }
    if(B == 0) cout << 1 << endl;
  }
  if(A == 8){
    B %= 4;
    if(B == 1) cout << 8 << endl;
    if(B == 2){
      C %= 4;
      if(C == 1) cout << 4 << endl;
      if(C == 2) cout << 6 << endl;
      if(C == 3) cout << 6 << endl;
      if(C == 0) cout << 6 << endl;
    }
    if(B == 3){
      C %= 4;
      if(C == 1) cout << 2 << endl;
      if(C == 2) cout << 8 << endl;
      if(C == 3) cout << 2 << endl;
      if(C == 0) cout << 8 << endl;
    }
    if(B == 0) cout << 6 << endl;
  }
  if(A == 9){
    B %=2;
    if(B == 1) cout << 9 << endl;
    if(B == 0) cout << 1 << endl;
  }
}
#include <bits/stdc++.h>
using namespace std;

int A, B, C;

int qp(int x, int y, int P) {
    int z = 1;
    for (; y; y >>= 1, x = 1LL * x * x % P) {
        if (y & 1) z = 1LL * z * x % P;
    }
    return z;
}

int main() {
    scanf("%d %d %d", &A, &B, &C);
    if (B <= 4 && C <= 4) {
        A = qp(A % 10, qp(B, C, 998244353), 10);
    } else {
        B = qp(B % 4, C, 4);
        A = qp(A % 10, B + 4, 10);
    }
    printf("%d\n", A);
    return 0;
}