A = {}
for target in input().split():
if target not in A:
A[target] = 1
else:
A[target] += 1
for word,result in (A.items()):
print(word, result)
n = int(input())
#チェック用の配列
re = []
for i in range(n):
s = input()
#もしsがre配列にあれば削除
if s in re:
re.pop(re.index(s))
#追加
re.append(s)
#最新から順番に(通常通りではない)
for i in range(len(re)):
print(re[-i - 1])