#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)

using namespace std;
using LL = long long;
using P = pair<int,int>;
using vv = vector<vector<int>>;
const int INF = (int)1e9;
const LL LINF = (LL)1e18;

long long const mod = 998244353;
struct mint{
	long long val;
	mint(long long val = 0): val(val % mod) {}
	mint& operator += (const mint n){
		val += n.val;
		if(val >= mod) val -= mod;
		return *this;
	}
	mint& operator -= (const mint n){
		val -= n.val;
		if(val < 0) val += mod;
		return *this;
	}
	mint& operator *= (const mint n){
		val *= n.val;
		val %= mod;
		if(val < 0) val += mod;
		return *this;
	}
	mint operator + (const mint n) const{
		mint res(*this);
		return res += n;
	}
	mint operator - (const mint n) const{
		mint res(*this);
		return res -= n;
	}
	mint operator * (const mint n) const{
		mint res(*this);
		return res *= n;
	}
	mint pow(long long n) const{
		if(n == 0) return 1;
		mint m = pow(n >> 1);
		m *= m;
		if(n & 1) m *= *this;
		return m;
	}
	// mint division for prime mod
	mint inv() const{
		return pow(mod - 2);
	}
	mint& operator /= (const mint n){
		return (*this) *= n.inv();
	}
	mint operator / (const mint n) const{
		mint res(*this);
		return res /= n;
	}
};

long long modpow(long long x, long long n){
	long long r = 1;
	while(n){
		if(n & 1) r = r * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return r;
}

int main(){
	LL N, M, K;
	cin >> N >> M >> K;
	if(N == 1){
		cout << modpow(K, M) << endl;
		return 0;
	}
	if(M == 1){
		cout << modpow(K, N) << endl;
		return 0;
	}
	mint ans = 0;
	for(LL i = 1; i <= K; i++){
		mint A = modpow(i, N) - modpow(i - 1, N);
		mint B = modpow(K - i + 1, M);
		mint res = A * B;
		ans += res;
	}
	cout << ans.val << endl;

	return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

void solve(){
  int n;
  cin >> n;
  if (n == 2 or n == 3) {
    cout << "1\n";
    return;
  }

  int fib[n];
  fib[0] = 1;
  fib[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fib[i] = add(fib[i-1],fib[i-2]);
  }

  char caa,cab,cba,cbb;
  cin >> caa >> cab >> cba >> cbb;

  if (cab == 'A') {
    if (caa == 'A') {
      cout << "1\n";
      return;
    }
    if (cba == 'A') {
      cout << fib[n-2] << "\n";
      return ;
    }
    else {
      cout << expo_pow(2,n-3) << "\n";
      return ;
    }
  }
  if (cab == 'B') {
    if (cbb == 'B') {
      cout << "1\n";
      return;
    }
    if (cba == 'B') {
      cout << fib[n-2] << "\n";
      return ;
    }
    else {
      cout << expo_pow(2,n-3) << "\n";
      return ;
    }
  }
  

}


signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}



