#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } #include using mint = atcoder::modint998244353; int main() { fast_io(); int l, k; cin >> l >> k; string s, t; cin >> s >> t; vector a(26); long long a_sum = 0; for (int i = 0; i < 26; i++) { cin >> a[i]; a_sum += a[i]; } vector p(26); { mint asum_inv = mint(a_sum).inv(); for (int i = 0; i < 26; i++) { p[i] = mint(a[i]) * asum_inv; } } // j: pn % l, x: pm - pn + l vector dp(k + 1, vector(l, vector(2 * l + 1, 0))); dp[0][0][l] = 1; for (int i = 0; i < k; i++) { for (int j = 0; j < l; j++) { dp[i + 1][j][0] += dp[i][j][0]; dp[i + 1][j][2 * l] += dp[i][j][2 * l]; for (int x = 1; x < 2 * l; x++) { int pn = j, pm = (j + x) % l; int pnn = s[pn] - 'a', pmm = t[pm] - 'a'; if (pnn == pmm) { dp[i + 1][(j + 1) % l][x] += dp[i][j][x] * p[pnn]; dp[i + 1][j][x] += dp[i][j][x] * (1 - p[pnn]); } else { dp[i + 1][(j + 1) % l][x - 1] += dp[i][j][x] * p[pnn]; dp[i + 1][j][x + 1] += dp[i][j][x] * p[pmm]; dp[i + 1][j][x] += dp[i][j][x] * (1 - p[pnn] - p[pmm]); } } } } mint ans_n = 0, ans_m = 0; for (int j = 0; j < l; j++) { ans_n += dp[k][j][0]; ans_m += dp[k][j][2 * l]; } cout << ans_n.val() << " " << ans_m.val() << endl; }