extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::BTreeMap;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

fn main() {
    loop {
        let_all!(n: usize);
        if n == 0 {
            return
        }
        let mut map = BTreeMap::new();
        let mut strength = Vec::<i32>::with_capacity(n);
        let mut neighbors = Vec::with_capacity(n);
        for _ in 0 .. n {
            let line = read_line!(' ');
            map.insert(line[0].clone(), strength.len());
            strength.push(line[1].parse().ok().unwrap());
            let mut n = Vec::with_capacity(line[2].parse().ok().unwrap());
            for i in 3 .. line.len() {
                n.push(line[i].clone());
            }
            neighbors.push(n);
        }
        let mut neighbor = vec![Vec::new(); n];
        for i in 0 .. n {
            for j in 0 .. neighbors[i].len() {
                neighbor[i].push(map[&neighbors[i][j]]);
            }
        }
        let mut memo = vec![vec![-1; 1 << (n / 2)]; n / 2];
        println!("{}", solve(n - 1, neighbor[0].iter().fold(1, |acc, &a| acc | (1 << a as i64)), &strength, &neighbor, &mut memo) + strength[0]);
    }
}
fn solve(current: usize, cant_use: i64, strength: &Vec<i32>, neighbors: &Vec<Vec<usize>>, memo: &mut Vec<Vec<i32>>) -> i32 {
    if current == 0 {
        if cant_use & 1 == 0 {
            strength[current]
        }else {
            0
        }
    }else if current < memo.len() {
        let state = (cant_use & ((1_i64 << memo.len() as i64) - 1)) as usize;
        match memo[current][state] {
            -1 => {
                let r = if cant_use & (1_i64 << current as i64) == 0 {
                    let not_use_current = solve(current - 1, cant_use, strength, neighbors, memo);
                    let use_current = solve(current - 1, neighbors[current].iter().fold(cant_use, |acc, &a| acc | (1_i64 << a as i64)), strength, neighbors, memo) + strength[current];
                    max(not_use_current, use_current)
                }else {
                    solve(current - 1, cant_use, strength, neighbors, memo)
                };
                memo[current][state] = r;
                r
            }
            cache => cache
        }
    }else {
        if cant_use & (1_i64 << current as i64) == 0 {
            let not_use_current = solve(current - 1, cant_use, strength, neighbors, memo);
            let use_current = solve(current - 1, neighbors[current].iter().fold(cant_use, |acc, &a| acc | (1_i64 << a as i64)), strength, neighbors, memo) + strength[current];
            max(not_use_current, use_current)
        }else {
            solve(current - 1, cant_use, strength, neighbors, memo)
        }
    }
}


Measured memory_bytes: 86972