N, M = map(int, input().split()) rating = {} for _ in range(N + M): name, rate = input().split() rating[name] = rate for name, rate in sorted(rating.items()): print(name, rate)