#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 1000000000000000000LL int main(){ int L,K; cin>>L>>K; string S,T; cin>>S>>T; vector a(26); mint sum = 0; rep(i,26){ cin>>a[i]; sum += a[i]; } vector p(26); rep(i,26){ p[i] = a[i]; p[i] /= sum; } vector dp(1,vector(1,1)); mint x = 0,y = 0; rep(i,K){ vector ndp(i+2,vector(i+2)); rep(j,i+1){ rep(k,i+1){ if(dp[j][k]==0)continue; int cx = S[j%L] - 'a'; int cy = T[k%L] - 'a'; if(cx==cy){ ndp[j+1][k+1] += dp[j][k] * p[cx]; ndp[j][k] += dp[j][k] * (1-p[cx]); } else{ ndp[j+1][k] += dp[j][k] * p[cx]; ndp[j][k+1] += dp[j][k] * p[cy]; ndp[j][k] += dp[j][k] * (1-p[cx]-p[cy]); } } } swap(dp,ndp); rep(j,i+2){ rep(k,i+2){ if(abs(j-k)==L){ if(j