#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        int mid = n/2;
        vi p(n),c(n);
        vector<vs> s(n);
        int id = 0;
        map<string,int> mp;
        rep(i,n){
            string t;
            cin >> t >> p[i] >> c[i];
            mp[t] = id++;
            s[i].resize(c[i]);
            rep(j,c[i]){
                cin >> s[i][j];
            }
        }
        vi st(mid),ed(n-mid),se(mid);
        vi sout((1 << mid),0);
        rep(i,mid){
            st[i] = (1 << i);
            rep(j,c[i]){
                int num = mp[s[i][j]];
                if(num >= mid){
                    se[i] |= (1 << (num-mid));
                }else{
                    st[i] |= (1 << num);
                }
            }
        }
        rep(i,n-mid){
            ed[i] = (1 << i);
            rep(j,c[i+mid]){
                int num = mp[s[i+mid][j]];
                if(num >= mid){
                    ed[i] |= (1 << (num-mid));
                }
            }
        }
        vector<bool> dst((1 << mid),false),ded((1 << (n-mid)),false);
        vi p1((1 << mid),0),p2((1 << (n-mid)),0);
        vector<int> mx((1 << (n-mid)),0);
        dst[0] = true;
        rep(i,(1 << mid)){
            if(dst[i]){
                rep(j,mid){
                    if(!((i >> j) & 1)){
                        if(!(i & st[j])){
                            dst[i^(1 << j)] = true;
                            sout[i^(1 << j)] = sout[i] | se[j];
                        }
                    }else{
                        p1[i] += p[j];
                    }
                }
            }
        }
        ded[0] = true;
        rep(i,(1 << (n-mid))){
            if(ded[i]){
                rep(j,n-mid){
                    if(!((i >> j) & 1)){
                        if(!(i & ed[j])){
                            ded[i^(1 << j)] = true;
                        }
                    }else{
                        p2[i] += p[j+mid];
                    }
                }
                mx[i] = p2[i];
            }else{
                rep(j,n-mid){
                    if((i >> j) & 1){
                        cmx(mx[i],mx[i^(1 << j)]);
                    }
                }
            }
        }
        int ans = 0;
        rep(i,(1 << mid)){
            if((i & 1) && dst[i]){
                cmx(ans,p1[i] + mx[((1 << (n-mid))-1) ^ sout[i]]);
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 19868