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 for _ in range(K): dd = [[0 for _ in range(2 * L - 1)] for _ in range(L)] for c in range(26): for i in range(L): for j in range(2 * L - 1): if d[i][j] == 0: continue ad = d[i][j] * a[c] % MOD xb, yb = S[i] == c, T[(i + j - L + 1) % L] == c if xb and yb: dd[(i + 1) % L][j] += ad elif xb: if j == 0: x += ad else: dd[(i + 1) % L][j - 1] += ad elif yb: if j == 2 * L - 2: y += ad else: dd[i][j + 1] += ad else: dd[i][j] += ad for i in range(L): for j in range(2 * L - 1): d[i][j] = dd[i][j] % MOD print(x % MOD, y % MOD)