import sys from collections import defaultdict input = lambda: sys.stdin.readline().rstrip() # ----------------------- # n, m = map(int, input().split()) sa = defaultdict(lambda: -1) for _ in range(n): s, a = input().split() sa[s] = a ans = [] for _ in range(m): t, b = input().split() sa[t] = b for k,v in sorted(sa.items()): print(k, v)