#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
using namespace std;
const int N = 100;
int main() {
int m, n;
cin >> m >> n;
unordered_map<string, int> hash;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
hash[s] = 0;
}
for (int i = 0; i < m; i++) {
string s;
cin >> s;
if (hash.find(s) != hash.end()) {
hash[s]++;
}
}
for (auto &[k, v] : hash) {
cout << k << " " << v << endl;
}
return 0;
}