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];
        groupId = new int[size];
    }

    int[] groupId;
    long[] group;
    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;

        group = new long[gidCount + 1];
        foreach (i; 1 .. gidCount + 1) {
            foreach (v; 0 .. size) {
                if (groupId[v] == i) {
                    group[i] |= (1L << v);
                }
            }
        }
    }

    int first(long flag) {
        foreach (i; 0 .. size) {
            if (flag & (1L << i)) return i;
        }
        assert(0);
    }

    int maximum() {
        int maxInGroup(int v, long used) {
            int ans = 0;
            void dfs(int v, long used, int cans) {
                if (v == size) {
                    ans = max(ans, cans);
                    return;
                }
                if (used & (1L << v)) {
                    dfs(v + 1, used, cans);
                    return;
                }
                int a = cans;
                foreach (i; 0 .. size) {
                    if (!(used & (1L << i))) {
                        a += value[i];
                    }
                }
                if (a <= ans) return;

                used |= (1L << v);
                long _used = used;

                foreach (u; next[v]) used |= (1L << u);
                dfs(v + 1, used, cans + value[v]);

                if (v == 0) return;

                used = _used;
                dfs(v + 1, used, cans);
            }
            dfs(v, used, 0);
            return ans;
        }

        initGroupId;
        int ret = 0;
        long u = 0;
        foreach (i; 1 .. gidCount + 1) {
            //writeln(i, " ", first(group[i]), " ", popcnt(group[i]));
            ret += maxInGroup(first(group[i]), ~group[i]);
        }
        //writeln("called ", called, " times.");
        return ret;
    }

    int n(int v, long used) {
        foreach (u; v + 1 .. size) {
            if (!(used & (1L << u))) return u;
        }
        return -1;
    }

    int popcnt(long x) {
        int c = 0;
        foreach (i; 0 .. size) {
            if (x & (1L << i)) {
                c++;
            }
        }
        return c;
    }
}

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.maximum.writeln;
    }
}