n, m = map(int, input().split()) dic = {} for _ in range(n + m): s, a = input().split() dic[s] = a key = list(dic.keys()) key.sort() for k in key: print(k, dic[k])