#!?usr/bin/env python3

import sys

def get_dict(filename):
	d = {}
	f = open(filename)
	for line in f:
		v = line.rstrip().split() 
		d[v[0]] = d.get(v[0], [])
		d[v[0]].append(line)
	return d

def get_common(d1, d2):
	s1 = set(list(d1.keys()))
	s2 = set(list(d2.keys()))
	c = s1.intersection(s2)
	for i in c:
		print(d1[i][0].rstrip())

	
if __name__ == '__main__':
	file1 = sys.argv[1]
	file2 = sys.argv[2]
	d1 = get_dict(file1)
	d2 = get_dict(file2)
	get_common(d1, d2)
