N,S=map(int,input().split())
Ans=[int(x) for x in input().split()]
M=int(input())
l=[]
for i in range(M):
l.append([int(x) for x in input().split()])
for i in range(M):
score=0
for j in range(N):
if l[i][j]==Ans[j]:
score+=S
print(score)