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}

		@pos = {}
		x = 1
		i = 0
		@n.times {
			@pos[x] = i
			x = (x << 1) | 1
			i += 1
		}

	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_zero?(i)
		tmp = subbits(i)
		tmp & (tmp - 1) == 0
	end

	def deg_one?(i)
		tmp = subbits(i)
		tmp &= (tmp - 1) 
		tmp & (tmp - 1) == 0
	end

	def subbits(i)
		(@bits >> i * @n) & ((1 << @n) -1 )
	end

	def opposite(i)
		tmp = subbits(i)
		tmp -= (1 << i)
		@pos[(tmp ^ (tmp - 1))]
	end

	def inspect
		a = (0..@n-1).map{|i|
				[$name[i], (0..@n-1).select{|j| subbits(i)[j] == 1 }.map{|j| $name[j]}]
			}
		Hash[*a.flatten(1)]
	end
end

def search(graph, weight, i)
	return 0 if i >= weight.size

	return search(graph, weight, i+1) if graph.deleted?(i)
	
	return weight[i] + search(graph, weight, i+1) if graph.deg_zero?(i)

	g = graph.dup
	g.select_node(i)
	x = weight[i] + search(g, weight, i+1)

	y = 0
	g = graph.dup
	if g.deg_one?(i)
		k = g.opposite(i)
		g.select_node(k)
		y = weight[k] + search(g, weight, i+1)		
	else
		g.del_node(i)
   	y = search(g, weight, i+1)
	end

	x > y ? x : y
end

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

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

		i = (index[country] ||= index.size)
		$name[i] = country
		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, 1)
}