#yuki1795 n,m=map(int,input().split()) d={} for i in range(n): s,a=input().split() d[s]=int(a) for i in range(m): s,a=input().split() d[s]=int(a) l=sorted(d) for x in l: print(x,d[x])