if __name__ == '__main__':
	t = int( input() )
	for i in range( t ) :
		n, m = list( map( int, input().split() ) )
		arr_1 = list( map( int, input().split() ) )
		arr_2 = list( map( int, input().split() ) )

		hast_table = [0 for i in range(1000) ] 

		for num in arr_1 :
			hast_table[ num - 1 ] += 1

		found = False
		for no in arr_2 :
			if hast_table[ no - 1 ] :
				found = True
				print( "YES" )
				print( 1, no )
				break

		if not found :
			print( "NO" )
