#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using Graph = vector< vector<int> >;

// generate binary string (not less than k-digit)
string to_binString(int n, int k) {
    string ret = "";
    while(n) ret += ('0' + (n&1)), n >>= 1;
    while(ret.length() < k) ret += '0';
    // reverse(ret.begin(), ret.end());
    return ret;
}

int N;

map<long long int, int> checked;

int solve(const Graph &G, const vector<int> &cost, vector<int> &deg, long long int bit) {
    if(checked.count(bit)) {
        return checked[bit];
    }

    long long int nbit;

    int ret = 0, tmp;

    // 次数最大の頂点
    int ma = -1, i = -1;
    for(int k=0; k<N; k++) {
        if(!(bit >> k & 1)) continue;
        if(deg[k] > ma) {
            ma = deg[k];
            i = k;
        }
    }

    if(i >= 0) {
        // その頂点を使う
        nbit = bit ^ (1LL << i); tmp = cost[i];
        vector<int> diff;
        for(auto v : G[i]) {
            if(nbit >> v & 1) {
                nbit ^= (1LL << v);
                for(auto to : G[v]) {
                    deg[to]--;
                    diff.push_back(to);
                }
            }
        }

        // 孤立している頂点
        for(int k=0; k<N; k++) {
            if(deg[k] == 0 && nbit >> k & 1) {
                tmp += cost[k];
                nbit ^= (1LL << k);
            }
        }

        tmp += solve(G, cost, deg, nbit);
        ret = max(ret, tmp);

        // 次数を元にもどす
        for(auto v : diff) deg[v]++;

        // 使わない
        nbit = bit ^ (1LL << i), tmp = 0;

        for(auto v : G[i]) deg[v]--;
        for(int k=0; k<N; k++) {
            if(deg[k] == 0 && nbit >> k & 1) {
                tmp += cost[k];
                nbit ^= (1LL << k);
            }
        }

        tmp += solve(G, cost, deg, nbit);
        ret = max(ret, tmp);

        for(auto v : G[i]) deg[v]++;
    }

    // printf("bit = %s, ret = %d\n", to_binString(bit, N).c_str(), ret);
    return checked[bit] = ret;
}

int main() {
    while(cin >> N, N) {
        checked.clear();
        map<string, int> mp;

        string root = "";
        vector<string> adj[50], name(N);
        vector<int> tmp(N), cost(N);
        for(int i=0; i<N; i++) {
            cin >> name[i];
            if(i == 0) {
                root = name[i];
            }

            mp[ name[i] ]++;
            cin >> tmp[i];

            int x; cin >> x;
            for(int k=0; k<x; k++) {
                string s; cin >> s;
                mp[s]++;
                adj[i].push_back(s);
            }
        }

        int id = 0;
        for(auto &x : mp) {
            x.second = id++;
        }

        Graph G(N);
        vector<int> deg(N);
        for(int i=0; i<N; i++) {
            int u = mp[ name[i] ];
            cost[u] = tmp[i];
            for(auto s : adj[i]) {
                int v = mp[s];
                G[u].push_back(v);
                G[v].push_back(u);
                deg[u]++; deg[v]++;
            }
        }

        long long int bit = (1LL << N) - 1;
        int root_v = mp[root], isolate = cost[root_v];

        // root_v に隣接する頂点
        bit ^= (1LL << root_v);
        for(auto v : G[root_v]) {
            if(bit >> v & 1) {
                bit ^= (1LL << v);
                for(auto to : G[v]) {
                    deg[to]--;
                }
            }
        }

        // 孤立している頂点
        for(int i=0; i<N; i++) {
            if(deg[i] == 0 && bit >> i & 1) {
                isolate += cost[i];
                bit ^= (1LL << i);
            }
        }

        cout << isolate + solve(G, cost, deg, bit) << endl;
    }
    return 0;
}


Measured memory_bytes: 4380