def knapsack(items, budget)
	table = (0..1).map{ Array.new(budget+1, 0) }
	for i in 0..items.size-1
		bits, v = items[i]
		for j in 0..budget
			x = table[0][j]
			y = (j & bits == bits ? table[0][j-bits] + v : 0)
			table[1][j] = x > y ? x : y
		end
		table << table.shift
	end
	table[0]
end

loop {
	n = gets.to_i
	break if n == 0
	guys = (1..n).map{
		k, value = gets.split.map &:to_i
		bits = 0
		k.times {
			s, t = gets.split.map &:to_i
			(s-6..t-7).each{|i|
				bits |= (1 << i)
			}
		}
		[bits, value]
	}
	p knapsack(guys, (1<<16)-1).max
}