def solution(keymap, targets):
answer = []
push = {}
for key in keymap:
for k in range(len(key)):
if key[k] not in push:
push[key[k]] = k+1
if push[key[k]] > k+1:
push[key[k]] = k+1
for t in targets:
ans = 0 ; k = 1
for i in t:
if i in push:
ans += push[i]
else:
k = 0
answer.append(-1)
break
if k == 1:
answer.append(ans)
return answer