N, M = map(int, input().split()) SA = [input().split() for _ in range(N)] TB = [input().split() for _ in range(M)] D = dict() for s, a in SA: D[s] = int(a) for t, b in TB: D[t] = int(b) for k in sorted(D.keys()): print(k, D[k])