n, m = map(int, input().split()) dic = {} for i in range(n): name, score = input().split() dic[name] = score for i in range(m): name, score = input().split() if name in dic: dic[name] = score else: dic[name] = score for k, v in sorted(dic.items(), key=lambda x:x[0]): print(k, v)