l,k = map(int,input().split()) s = [ord(v)-97 for v in input()] t = [ord(v)-97 for v in input()] a = list(map(int,input().split())) dp = [[0]*2*l for _ in range(2*l)] dp[0][0] = 1; x = y = 0; z = 998244353 n = sum(a); d = pow(n,-1,z) for _ in range(k): eq = [[0]*2*l for _ in range(2*l)] for i in range(2*l): for j in range(2*l): if i>=l<=j or abs(i-j)>=l or dp[i][j]==0: continue for v,c in enumerate(a): p = dp[i][j]*c%z*d%z if s[i%l]==t[j%l]==v: if i+1>=l<=j+1: eq[(i+1)%l][(j+1)%l] += p else: eq[i+1][j+1] += p elif s[i%l]==v: if i+1-j==l: x += p elif i+1>=l<=j: eq[(i+1)%l][j%l] += p else: eq[i+1][j] += p elif t[j%l]==v: if j+1-i==l: y += p elif i>=l<=j+1: eq[i%l][(j+1)%l] += p else: eq[i][j+1] += p else: eq[i][j] += p dp = [[eqij%z for eqij in eqi] for eqi in eq] print(x%z,y%z)