N,M = map(int,input().split()) dic = {} for _ in range(N): S,A = input().split() dic[S] = A for _ in range(M): T,B = input().split() dic[T] = B ans = [] for k,v in dic.items(): ans.append((k, v)) ans.sort() for k,v in ans: print(k, v)