import sys input = sys.stdin.readline from collections import * N, M = map(int, input().split()) D = defaultdict(int) for i in range(N): s, a = input().split() D[s] = int(a) for i in range(M): t, b = input().split() D[t] = int(b) for k in sorted(D.keys()): print(k, D[k])