L,K=map(int,input().split()) s=list(input()) for i in range(L): s[i]=ord(s[i])-ord("a") t=list(input()) for i in range(L): t[i]=ord(t[i])-ord("a") a=list(map(int,input().split())) M=998244353 A=sum(a) iA=pow(A,M-2,M) X=10**10 w1=0 w2=0 q=[[0]*(2*L+1) for i in range(L)] q[0][0]=1 import gc for _ in range(K): nq=[[0]*(2*L+1) for i in range(L)] for i in range(L): for l in range(-L+1,L): j=(i-l)%L if s[i]==t[j]: nq[(i+1)%L][l]+=q[i][l]*a[s[i]]*iA nq[i][l]+=q[i][l]*(A-a[s[i]])*iA else: nq[(i+1)%L][l+1]+=q[i][l]*a[s[i]]*iA nq[i][l-1]+=q[i][l]*a[t[j]]*iA nq[i][l]+=q[i][l]*(A-a[s[i]]-a[t[j]])*iA q=nq for i in range(L): w1+=q[i][L] w2+=q[i][-L] print(w1%M,w2%M)