L,K=map(int,input().split()) S=input().strip() T=input().strip() mod=998244353 S2=[] T2=[] for s in S: S2.append(ord(s)-97) for t in T: T2.append(ord(t)-97) A=list(map(int,input().split())) SUM=sum(A) INV=pow(SUM,mod-2,mod) DP=[[0]*(K+1) for i in range(K+1)] DP[0][0]=1 for tt in range(K): NDP=[[0]*(K+1) for i in range(K+1)] for i in range(tt+1): for j in range(tt+1): if abs(i-j)==L: NDP[i][j]+=DP[i][j] continue x=S2[i%len(S2)] y=T2[j%len(T2)] if x==y: NDP[i+1][j+1]+=DP[i][j]*A[x]*INV NDP[i][j]+=DP[i][j]*(SUM-A[x])*INV NDP[i][j]%=mod NDP[i+1][j+1]%=mod else: NDP[i+1][j]+=DP[i][j]*A[x]*INV NDP[i][j+1]+=DP[i][j]*A[y]*INV NDP[i][j]+=DP[i][j]*(SUM-A[x]-A[y])*INV NDP[i+1][j]%=mod NDP[i][j+1]%=mod NDP[i][j]%=mod DP=NDP ANS1=0 ANS2=0 for i in range(K+1): for j in range(K+1): if i-j==L: ANS1+=DP[i][j] if j-i==L: ANS2+=DP[i][j] print(ANS1%mod,ANS2%mod)