#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 16;

struct MaximumIndependentSet {
    using T = int;
    MaximumIndependentSet(const int n) : n{n}, former{n / 2}, latter{n - former}, former_maximum{1LL << former}, latter_maximum{1LL << latter}, cost(n, 1), elist(n), former_dp(former_maximum, 0), latter_dp(latter_maximum, 0), former_next(former_maximum, latter_maximum - 1LL) {}
    MaximumIndependentSet(const vector<T>& cost) : n(cost.size()), former{n / 2}, latter{n - former}, former_maximum{1LL << former}, latter_maximum{1LL << latter}, cost{cost}, elist(n), former_dp(former_maximum, 0), latter_dp(latter_maximum, 0), former_next(former_maximum, latter_maximum - 1LL) {}
    void addEdge(const int from, const int to)
    {
        assert(0 <= from);
        assert(from < n);
        assert(0 <= to);
        assert(to < n);
        elist[from].push_back(to);
        elist[to].push_back(from);
    }

    T calculate()
    {
        if(n==0){
            return 0;
        }else if (n == 1) {
            return max(cost[0], static_cast<T>(0));
        }
        for (ll i = 0; i < latter_maximum; i++) {
            for (int j = 0; j < latter; j++) {
                if (i & (1LL << j)) {
                    ll mask = i - (1LL << j);
                    for (const int to : elist[j + former]) {
                        if (to >= former) {
                            if (i & (1LL << (to - former))) {
                                mask &= ~(1LL << (to - former));
                            }
                        }
                    }
                    latter_dp[i] = max(latter_dp[i - (1LL << j)], latter_dp[mask] + cost[j + former]);
                    break;
                }
            }
        }

        T maximum = latter_dp[latter_maximum - 1];
        for (ll i = 1; i < former_maximum; i++) {
            for (int j = 0; j < former; j++) {
                if (i & (1LL << j)) {
                    if (former_dp[i - (1LL << j)] != -INF<T>) {
                        bool ok = true;
                        ll mask = former_next[i - (1LL << j)];
                        for (const int to : elist[j]) {
                            if (to >= former) {
                                mask &= ~(1LL << (to - former));
                            } else {
                                if (i & (1LL << to)) {
                                    ok = false;
                                    break;
                                }
                            }
                        }
                        if (ok) {
                            former_dp[i] = former_dp[i - (1LL << j)] + cost[j];
                            former_next[i] = mask;
                            maximum = max(maximum, former_dp[i] + latter_dp[mask]);
                        } else {
                            former_dp[i] = -INF<T>;
                        }
                    }
                    break;
                }
            }
        }
        return maximum;
    }

    const int n;
    const int former;
    const int latter;
    const ll former_maximum;
    const ll latter_maximum;
    const vector<T> cost;
    vector<vector<int>> elist;
    vector<T> former_dp;
    vector<T> latter_dp;
    vector<ll> former_next;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (true) {
        int N;
        cin >> N;
        if (N == 0) {
            break;
        }
        map<string, int> id;
        vector<vector<string>> neighbor(N);
        vector<int> power(N);
        for (int i = 0; i < N; i++) {
            string s;
            cin >> s;
            id[s] = i;
            int B;
            cin >> B;
            power[i] = B;
            int C;
            cin >> C;
            for (int j = 0; j < C; j++) {
                string d;
                cin >> d;
                neighbor[i].push_back(d);
            }
        }
        set<int> far;
        for (int i = 1; i < N; i++) {
            far.insert(i);
        }
        for (const string& s : neighbor[0]) {
            far.erase(id[s]);
        }
        const int size = far.size();
        map<int, int> mp;
        int cnt = 0;
        for (const int f : far) {
            mp[f] = cnt;
            cnt++;
        }

        vector<int> B;
        for (const int f : far) {
            B.push_back(power[f]);
        }
        MaximumIndependentSet st{B};
        for (const int f : far) {
            for (const string& name : neighbor[f]) {
                const int ind = id[name];
                if (far.find(ind) != far.end()) {
                    st.addEdge(mp[f], mp[ind]);
                }
            }
        }
        cout << power[0] + st.calculate() << endl;
    }
    return 0;
}

Measured memory_bytes: 13392