#include namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair; using VI = vector; using VVI = vector; using VL = vector; using VVL = vector; using mint = modint998244353; } int main() { ios::sync_with_stdio(false); cin.tie(0); int l, k; cin >> l >> k; string s, t; cin >> s >> t; mint a[26]; rep(i, 26) { int x; cin >> x; a[i] = x; } mint denom = accumulate(all(a), mint()).inv(); mint dp[50][101]; dp[0][50] = 1; mint ans1, ans2; rep(_, k) { mint ndp[50][101]; rep(i, l) for (int diff = -l + 1; diff <= l - 1; diff++) { int j = (i + diff + l) % l; int ni = (i + 1) % l, nj = (j + 1) % l; int ci = s[i] - 'a', cj = t[j] - 'a'; if (ci == cj) { ndp[ni][50 + diff] += dp[i][50 + diff] * (a[ci] * denom); ndp[i][50 + diff] += dp[i][50 + diff] * (1 - a[ci] * denom); } else { ndp[ni][50 + diff - 1] += dp[i][50 + diff] * (a[ci] * denom); ndp[i][50 + diff + 1] += dp[i][50 + diff] * (a[cj] * denom); ndp[i][50 + diff] += dp[i][50 + diff] * (1 - (a[ci] + a[cj]) * denom); } } rep(i, l) { ans1 += ndp[i][50 - l]; ans2 += ndp[i][50 + l]; } rep(i, 50) rep(j, 101) dp[i][j] = ndp[i][j]; } cout << ans1.val() << ' ' << ans2.val() << '\n'; }