import sys input = sys.stdin.readline MOD = 998244353 L, K = map(int, input().split()) S = input().strip() T = input().strip() A = list(map(int, input().split())) C = sum(A) base = pow(C, MOD-2, MOD) Q = [] for a in A: Q.append(a*base%MOD) #print(Q) dp = dict() dp[(0, 0)] = 1 X = 0 Y = 0 for i in range(K): ndp = dict() for key in dp: pn, pm = key if pn-pm==L: X += dp[key] X %= MOD continue if pm-pn==L: Y += dp[key] Y %= MOD continue sn = S[pn%L] sm = T[pm%L] if sn==sm: snc = ord(sn)-ord('a') if Q[snc]>0: if (pn+1, pm+1) not in ndp: ndp[(pn+1, pm+1)] = dp[key] * Q[snc] % MOD else: ndp[(pn+1, pm+1)] += dp[key] * Q[snc] % MOD ndp[(pn+1, pm+1)] %= MOD if (1-Q[snc])%MOD>0: if (pn, pm) not in ndp: ndp[(pn, pm)] = dp[key] * (1-Q[snc]) % MOD else: ndp[(pn, pm)] += dp[key] * (1-Q[snc]) % MOD ndp[(pn, pm)] %= MOD else: snc = ord(sn)-ord('a') smc = ord(sm)-ord('a') if Q[snc]>0: if (pn+1, pm) not in ndp: ndp[(pn+1, pm)] = dp[key] * Q[snc] % MOD else: ndp[(pn+1, pm)] += dp[key] * Q[snc] % MOD ndp[(pn+1, pm)] %= MOD if Q[smc]>0: if (pn, pm+1) not in ndp: ndp[(pn, pm+1)] = dp[key] * Q[smc] % MOD else: ndp[(pn, pm+1)] += dp[key] * Q[smc] % MOD ndp[(pn, pm+1)] %= MOD if (1-Q[snc]-Q[smc])%MOD>0: if (pn, pm) not in ndp: ndp[(pn, pm)] = dp[key] * (1-Q[snc]-Q[smc]) % MOD else: ndp[(pn, pm)] += dp[key] * (1-Q[snc]-Q[smc]) % MOD ndp[(pn, pm)] %= MOD dp = ndp #print(dp) #print(X, Y) for key in dp: pn, pm = key if pn-pm==L: X += dp[key] X %= MOD continue if pm-pn==L: Y += dp[key] Y %= MOD continue print(X, Y)