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 }
		@mask = (0..@n-1).map{|i| @ones << i}
	end

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

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

	def select_node(i)
		@bits -= (@bits & @mask[i])
	end

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

	def deg(i)
		(i*@n .. (i+1)*@n-1).count{|j| @bits[j] == 1} - (deleted?(i) ? 0 : 1)
	end

	def opposite(i)
		j = i * @n 
		j += 1 until j % @n != i && @bits[j] == 1
		j % @n
	end

end

def search(graph, weight, i)
	return 0 if i >= weight.size
	
	base = 0
	for j in i..weight.size-1
		if !graph.deleted?(j) && graph.deg(j) == 0
			graph.select_node(j)
			base += weight[j]
		end
	end

	max = base	
	for j in i..weight.size-1
		next if graph.deleted?(j)

		g = graph.dup
		g.select_node(j)
		ret = base + weight[j] + search(g, weight, j+1)	
		max = ret if ret > max

		if graph.deg(j) == 1
			k = graph.opposite(j)
			graph.select_node(k)
			base += weight[k]
			max = base if base > 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)
}