class GraphBits
	def initialize(n)
		@n = n
		@bits = 1
		(n-1).times { @bits = (@bits << @n + 1) | 1 }
		@ones = 1
		(n-1).times { @ones = (@ones << @n) | 1 }
	end

	def add_edge(i, j)
		@bits |= (1 << i * @n + j)
	end

	def del_node(i)
		tmp = @bits & (@ones << i)
		@bits -= tmp
	end

	def select_node(i)
		del_node(i)
		(0..@n-1).each{|j|
			del_node(j) if @bits[i * @n + j] == 1
		}
	end

	def deleted?(i)
		@bits[i * @n + i] == 0
	end

end


def search(graph, weight, i)
	return 0 if i >= weight.size
	max = 0	
	for j in i..weight.size-1
		unless graph.deleted?(j)
			g = graph.dup
			g.select_node(j)
			ret = weight[j] + search(g, weight, j+1)	
			max = ret if ret > max
		end
	end
	max
end
	

loop {
	n = gets.to_i
	break if n == 0

	index = {}
	graph = GraphBits.new(n)
	weight = Array.new(n)
		
	n.times {
		country, weight_str, _, *neighbours = gets.split

		i = (index[country] ||= index.size)
		weight[i] = weight_str.to_i

		neighbours.each{|neighbour|
			j = (index[neighbour] ||= index.size)
			graph.add_edge(i, j)
		}
	}

	graph.select_node(0)
	p weight[0] + search(graph, weight, 0)
}