#include <iostream>
#include <string>
#include <map>
using namespace std;
map<string, int> mymap;
int main()
{
int i, m, n, point, ans;
string str, word;
cin >> m >> n;
for (i = 0; i < m; i++){
cin >> str >> point;
mymap[str] = point;
}
for (i = 0; i < n; i++){
ans = 0;
while (cin >> word){
if (word == ".") break;
if (mymap[word] != 0)
ans += mymap[word];
}
cout << ans << endl;
}
system("pause");
}
09-26