// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int n;
int main(){
	while(cin>>n,n){
		map<string,int>ma;
		vs name(n);
		vi b(n),co(n);
		vector<vs>in(n);
		rep(i,n){
			cin>>name[i]>>b[i]>>co[i];
			ma[name[i]]=1;
			in[i]=vs(co[i]);
			rep(j,co[i]){
				cin>>in[i][j];
				ma[in[i][j]]=1;
			}
		}
		int t=0;
		rep(i,n)ma[name[i]]=i;
	
		vector<ll>A(n);
		rep(i,n)rep(j,in[i].size()){
			int from=ma[name[i]],to=ma[in[i][j]];
			A[from]|=1ll<<to;
		}
		int N=n/2,nN=n-N;
		
//		rep(i,n){
//			cout<<name[i]<<" ";
//			rep(j,n)cout<<((A[i]&1<<j)>>j)<<" ";cout<<endl;
//		}
		vi dp(1<<nN);
		rep(i,1<<nN){
			bool h=true;
			rep(j,nN)if((i&1<<j)&&((i&A[j+N]>>N)))h=false;
			if(h){
				int sum=0;
				rep(j,nN)if(i&1<<j)sum+=b[N+j];
				dp[i]=max(dp[i],sum);
			}
			rep(j,nN)if((i&1<<j)==0)
				dp[i|1<<j]=max(dp[i|1<<j],dp[i]);
		}
		
		int out=0;
		rep(i,1<<N)if(i&1){
			bool h=true;
			int sum=0;
			rep(j,N)if((i&1<<j)){
				sum+=b[j];
				if(i&A[j])h=false;
			}
			if(h){
				t=(1<<nN)-1;
				rep(j,N)if((i&1<<j))t&=~(A[j]>>N);
				out=max(out,sum+dp[t]);
			}			
		}
		cout<<out<<endl;
	}
}



/*
int n,m;
vi A,B;
int dp[52][52][110][2][3];
int mem[52][52][110][2][3];
int f(int a,int b,int co,int tu,int pas){
    if(mem[a][b][co][tu][pas]+inf)return mem[a][b][co][tu][pas];
	if(pas==3)
	
    int A,B,TU=(tu+co)%2;
    if(!tu)A=a+(1+co)/2,B=b+co/2;
    else A=a+co/2,B=b+(1+co)/2;
    if(TU==0){
        int ma=-inf;
        if(A<n)ma=max(ma,f(a,b,co+1,tu,0));
        if(co)ma=max(ma,dp[a][b][co][tu]+f(A,B,0,TU^1,pas+1));
        else if(a+b+co)ma=max(ma,0);
        cout<<" "<<a<<" "<<b<<" "<<co<<" "<<tu<<" "<<ma<<" "<<dp[a][b][co][tu]<<endl;
        return mem[a][b][co][tu]=ma;
    }else{
        int mi=inf;
        if(B<m)mi=min(mi,f(a,b,co+1,tu,0));
        if(co)mi=min(mi,dp[a][b][co][tu]+f(A,B,0,TU^1,pas+1));
        else mi=min(mi,0);
        cout<<a<<" "<<b<<" "<<co<<" "<<tu<<" "<<mi<<endl;
        return mem[a][b][co][tu]=mi;
    }
}
int main(){
    cin>>n>>m;
    A=vi(n);rep(i,n)cin>>A[i];
    B=vi(m);rep(i,m)cin>>B[i];
     
    rep(l,2)rep(i,n+1)rep(j,m+1){
        int sum=0;
        int L=l,I=i,J=j;
        int co=0;
        while(1){
            dp[i][j][co][l]=sum;
            if(L&&J>=m||!L&&I>=n)break;
            if(L){
                if(B[J]+1)sum-=B[J];
                else sum=0;
                J++;
            }else{
                if(A[I]+1)sum+=A[I];
                else sum=0;
                I++;
            }
            L^=1;
            co++;
        }
    }   
//    rep(i,3)rep(j,3){rep(k,5)cout<<" "<<dp[i][j][k][0];cout<<endl;}
//    rep(i,3)rep(j,3){rep(k,5)cout<<" "<<dp[i][j][k][1];cout<<endl;}
    rep(i,52)rep(j,52)rep(k,110)rep(l,2)rep(q,3)
        mem[i][j][k][l][q]=-inf;
    cout<<f(0,0,0,0,1)<<endl;
}
*/


Measured memory_bytes: 7284