import sys input = sys.stdin.readline L, K = map(int, input().split()) S = [ord(c) - ord("a") for c in input().strip()] T = [ord(c) - ord("a") for c in input().strip()] a = list(map(int, input().split())) a_sum = sum(a) MOD = 998244353 a_sum_inv = pow(a_sum, MOD - 2, MOD) for i in range(26): a[i] = a[i] * a_sum_inv % MOD d = [[0 for _ in range(2 * L - 1)] for _ in range(L)] d[0][L - 1] = 1 x, y = 0, 0 dd = [[0 for _ in range(2 * L - 1)] for _ in range(L)] for _ in range(K): for i in range(L): for j in range(2 * L - 1): dd[i][j] = 0 for i in range(L): for j in range(2 * L - 1): if d[i][j] == 0: continue c1, c2, c3, c4 = 0, 0, 0, 0 for c in range(26): xb, yb = S[i] == c, T[(i + j - L + 1) % L] == c if xb and yb: c1 += a[c] elif xb: c2 += a[c] elif yb: c3 += a[c] else: c4 += a[c] ad = d[i][j] * a[c] % MOD dd[(i + 1) % L][j] += d[i][j] * c1 % MOD if j == 0: x += d[i][j] * c2 % MOD else: dd[(i + 1) % L][j - 1] += d[i][j] * c2 % MOD if j == 2 * L - 2: y += d[i][j] * c3 % MOD else: dd[i][j + 1] += d[i][j] * c3 % MOD dd[i][j] += d[i][j] * c4 % MOD for i in range(L): for j in range(2 * L - 1): d[i][j] = dd[i][j] % MOD print(x % MOD, y % MOD)