#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);
            }
        }
        constexpr int LARGE = INF<int> / 16;
        int ans = power[0] - LARGE;
        power[0] = LARGE;
        MaximumIndependentSet g{power};
        for (int i = 0; i < N; i++) {
            for (const string& s : neighbor[i]) {
                g.addEdge(i, id[s]);
            }
        }
        cout << ans + g.calculate() << endl;
    }
    return 0;
}

Measured memory_bytes: 19568