#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define N 1000000000
#define inf 10000000000000

ll T,n,m,k,t,mi,mc=0;
ll a,b,c;

inline ll ksm(ll a,ll b,ll mod){ ll res=1;
    for(;b;b>>=1,a=a*a%mod){
        if(b&1)res=res*a%mod;
        a=a*a%mod;
    }
    return res;
}

ll g[10][10]={
    0,0,0,0,0,0,0,0,0,0,
    1,1,1,1,1,1,1,1,1,1,
    6,2,4,8,6,2,4,8,6,2,
    1,3,9,7,1,3,9,7,1,3,
    6,4,6,4,6,4,6,4,6,4,
    5,5,5,5,5,5,5,5,5,5,
    6,6,6,6,6,6,6,6,6,6,
    1,7,9,3,1,7,9,3,1,7,
    6,8,4,2,6,8,4,2,6,8,
    1,9,1,9,1,9,1,9,1,9,
};
ll f[10]={1,1,4,4,2,1,1,4,4,2};

inline ll read(){
    ll f=0,s=0; char c=getchar();
    while(c>'9'||c<'0')f=(c=='-'),c=getchar();
    while(c>='0'&&c<='9')s=(s<<3)+(s<<1)+(c^'0'),c=getchar();
    return f?-s:s;
}

int main(){
    a=read(); b=read(); c=read();
    if(b==0&&c==0){
        printf("%lld",a%10);
        return 0;
    }
    else if(b==0){
        puts("1");
        return 0;
    }
    else{
        if(a%10==0){
            puts("0");
            return 0;
        }
    }
    ll k=ksm(b,c,f[a%10]); //cout<<k<<endl;
    printf("%lld",g[a%10][k]);
    return 0;
}
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define it register int
#define ct const int
#define il inline
template <class I> 
il I Max(I p,I q){return p>q?p:q;}
template <class I> 
il I Min(I p,I q){return p<q?p:q;}
template <class I> 
il I A(I x){return x<0?-x:x;}
template <class I> 
il void sp(I&p,I&q){I x=p;p=q,q=x;}
template <class I>
il void ckMax(I&p,I q){p=(p>q?p:q);}
template <class I>
il void ckMin(I&p,I q){p=(p<q?p:q);}
const int N=1000005,P=998244353;
il void mo(it &p,ct q){p+=q,p>=P?p-=P:0;}
int pw[N],n,m;
il int ksm(it x,it L){it ans=1;while(L) L&1?ans=(0ll+ans)*x%P:0,x=(0ll+x)*x%P,L>>=1;return ans;}	
int main(){ 
	scanf("%d%d",&n,&m);it i,j;
	for(i=pw[0]=1;i<=5000;++i) pw[i]=(0ll+pw[i-1])*m%P;
	it ans=(0ll+n)*ksm(m,n)%P;
	for(i=1;i<n;++i) for(j=1;j<=m;++j) ans=(ans-(0ll+pw[n-i-1])*(0ll+n-i)%P*ksm(m-j,i-1))%P;
	printf("%d",(ans+P)%P);
	return 0;
}

