def solve(n, d, l, r)
    return $h[r] if $h.has_key?(r)
    max = 0
    n.times do |i|
        if r & d[i] == d[i]
            ret = l[i] + solve(n, d, l, r - d[i]) 
            max = ret if ret > max
        end
    end
    return $h[r] = max
end
loop do
    $h = Hash.new
    n = gets.to_i
    break if n == 0
    d = Array.new(n, 0)
    l = Array.new(n)
    n.times do |p|
        m, l[p] = gets.split.map(&:to_i)
        m.times do
            t = gets.split.map(&:to_i)
            for i in ((t[0] - 6)...(t[1] - 6))
                d[p] += 1 << i
            end
        end
    end
    p solve(n, d, l, (1 << 16) - 1)
end