from collections import defaultdict n, m = map(int, input().split()) Rate = defaultdict(int) for _ in range(n): s, a = input().split() Rate[s] = int(a) for _ in range(m): t, b = input().split() Rate[t] = int(b) ANS = [(name, score) for name, score in Rate.items()] ANS.sort(key=lambda x: x[0]) for name, score in ANS: print(name, score)