import std.stdio;
import std.functional;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

class Graph {
    int[] value;
    int[][] next;
    int size;
    this(int size) {
        this.size = size;
        value = new int[size];
        next = new int[][size];
    }
    int max() {
        int[] groupId = new int[size]; // 連結グラフの集合に分割する
        int gidCount;
        void initGroupId() {
            void dfs(int v, int id) {
                groupId[v] = id;
                foreach (u; next[v]) {
                    if (!groupId[u]) {
                        dfs(u, id);
                    }
                }
            }
            int cid = 0;
            foreach (v; 0 .. size) {
                if (!groupId[v]) dfs(v, ++cid);
            }
            gidCount = cid;
        }
        initGroupId;

        int dfs(int v, long used) {
            int gid = groupId[v];
            if (used & (1L << v)) return 0;

            used |= (1L << v);

            long _used = used;

            foreach (u; next[v]) used |= (1L << u);
            int ret = value[v];
            foreach (u; 0 .. size) {
                if (!(used & (1L << u)) && groupId[u] == gid) {
                    ret += dfs(u, used);
                    break;
                }
            }

            if (v == 0) return ret;

            used = _used;

            foreach (u; next[v]) {
                if (!(used & (1L << u)) && groupId[u] == gid) {
                    ret = std.algorithm.max(ret, dfs(u, used));
                    break;
                }
            }

            return ret;
        }
        
        int ret = 0;
        foreach (i; 1 .. gidCount + 1) {
            foreach (j; 0 .. size) {
                if (groupId[j] == i) {
                    //[i, groupId.count(i)].writeln;
                    ret += dfs(j, 0);
                    break;
                }
            }
        }
        return ret;
    }
}

void main() {
    int N; 
    while (readf("%d\n", &N), N) {
        int[string] id; int cid = 0;
        Graph g = new Graph(N);
        foreach (i; 0 .. N) {
            string A; int B, C;
            readf("%s %d %d", &A, &B, &C);
            if (id.get(A, -1) == -1) id[A] = cid++;
            g.value[id[A]] = B;
            if (C != 0) readf(" ");
            string[] Ds = readln.chomp.split(" ");
            foreach (D; Ds) {
                if (id.get(D, -1) == -1) id[D] = cid++;
                g.next[id[A]] ~= id[D];
            }
        }
        g.max.writeln;
    }
}