#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int> > pipii;
typedef vector<int> vi;

const int INF = 1e9;
const int MOD = 1e9+7;

typedef struct c{
    int id;
    vector<string> nes;
    string name;
    int power;
    ll ne;
} country;

typedef pair<int, pair<int, ll> > data;

int calc(vector<country> &cs){
    int n = cs.size();
    int res = 0;
    ll ne = cs[0].ne;
    int power = cs[0].power;
    REP(i, n){
        if((ne & (1LL<<i)) != 0) continue;
        if(((ne | cs[i].ne) ^ (ne | (1LL<<i))) < 1LL){
            ne |= cs[i].ne;
            power += cs[i].power;
        }
    }
    
    priority_queue<data> pq;

    pq.push(data(0, pair<int, ll>(power, ne)));

    while(!pq.empty()){
        ne = pq.top().second.second;
        power = pq.top().second.first;
        int v = pq.top().first + 1;
        pq.pop();
        //cout << v << "*" << power << ":" << ne << endl;
        res = max(res, power);
        
        while(((ne & (1LL << v)) != 0LL) && v < n) v++;
        if(v == n) continue;
        
        int sum = power;
        for(int i = v; i < n; i++){
            if(((1LL<<i) & ne) == 0) sum += cs[i].power;
        }
        //cout << sum << "sum: res " << res << endl;
        if(sum < res) continue;
        
        ll nne = ne;
        int npower = power;
        for(int i = v + 1; i < n; i++){
            if((nne & (1LL<<i)) != 0) continue;
            if(((nne | cs[i].ne) ^ (nne | (1LL<<i))) < (1LL <<(v+1))){
                nne |= cs[i].ne;
                npower += cs[i].power;
            }
        }
        pq.push(data(v, pair<int, ll>(npower, nne)));
        
        
        ne |= cs[v].ne;
        power += cs[v].power;
        for(int i = v + 1; i < n; i++){
            if(ne & (1LL<<i) != 0) continue;
            if(((ne | cs[i].ne) ^ (ne | (1LL<<i))) < (1LL <<(v+1))){
                ne |= cs[i].ne;
                power += cs[i].power;
            }
        }
        pq.push(data(v, pair<int, ll>(power, ne)));
    }
    return res;
}

int main(void){
    int n;
    while(cin >> n, n){
        vector<country> cs(n);
        map<string, int> cnames;
        REP(i, n){
            int c;
            cs[i].id = i;
            cin >> cs[i].name >> cs[i].power;
            cnames[cs[i].name] = i;
            cs[i].ne = 0LL;
            cin >> c;
            REP(j, c){
                string s;
                cin >> s;
                cs[i].nes.push_back(s);
            }
        }
        REP(i, n){
            cs[i].ne |= (1LL<<i);
            REP(j, cs[i].nes.size()){
                int k = cnames[cs[i].nes[j]];
                cs[i].ne |= (1LL<<k);    
            }
        }
        cout << calc(cs) << endl;         
    }

    return 0;
}

Measured memory_bytes: 1348