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 j in range(L)] for i in range(L)] q[0][0][0]=1 for _ in range(K): nq=[[[0]*(2*L+1) for j in range(L)] for i in range(L)] for i in range(L): for j in range(L): for l in range(-L+1,L): for c in range(26): nq[(i+(c==s[i]))%L][(j+(c==t[j]))%L][l+(c==s[i])-(c==t[j])]+=q[i][j][l]*a[c]*iA nq[(i+(c==s[i]))%L][(j+(c==t[j]))%L][l+(c==s[i])-(c==t[j])]%=M q=nq for i in range(L): for j in range(L): w1+=q[i][j][L] w1%=M w2+=q[i][j][-L] w2%=M print(w1,w2)