#include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif mint dp[505][505][505]; int main() { int l, k; cin >> l >> k; string S, T; cin >> S >> T; int n = 26; vector a(n); rep(i,n) cin >> a[i]; int all = accumulate(a.begin(),a.end(),0); dp[0][0][0] = 1; vector p(n); rep(i,n) p[i] = mint(a[i]) * mint(all).inv(); rep(i,k) { for(int j=0;j<=k;j++)for(int h=0;h<=k;h++) { if(abs(j-h)>=l) continue; if(dp[i][j][h]==0) continue; dbg(i,j,h); rep(t,n) { if(t==S[j%l]-'a') dp[i+1][j+1][h] += dp[i][j][h]*p[t]; if(t==T[h%l]-'a') dp[i+1][j][h+1] += dp[i][j][h]*p[t]; if(t!=S[j%l]-'a' && t!=T[h%l]-'a') { dp[i+1][j][h] += dp[i][j][h]*p[t]; } } } } mint A, B; for(int i=1;i<=k;i++) for(int j=0;j<=k;j++) for(int h=0;h<=k;h++) { if(j-h==l) A += dp[i][j][h]; if(h-j==l) B += dp[i][j][h]; } cout << A.val() << " " << B.val() << endl; return 0; }