#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,int>
                                        #define ppa pair<int,int>
                                        #define ppap pair<int,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-12)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
                                        
                                  class pas{
                                    	public:
                                    	int x,y;
                                    	pas(int x=0,int y=0):x(x),y(y) {}
                                    	pas operator + (pas p) {return pas(x+p.x,y+p.y);}
                                    	pas operator - (pas p) {return pas(x-p.x,y-p.y);}
                                    	pas operator * (int a) {return pas(x*a,y*a);}
                                    	pas operator / (int a) {return pas(x/a,y/a);}
                                    //	double absv() {return sqrt(norm());}
                                    	int norm() {return x*x+y*y;}
                                    	bool operator < (const pas &p) const{
                                   		return x != p.x ? x<p.x: y<p.y;
                                   	}
                                  //		bool operator < (const pas &p) const{
                                    //		return y != p.y ? y<p.y: x<p.x;
                                    //	}
                                    	bool operator == (const pas &p) const{
                                    		return x==p.x && y==p.y;
                                    	}
                                    };

                                        class Point{
                                        	public:
                                        	double x,y;
                                        	Point(double x=0,double y=0):x(x),y(y) {}
                                        	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
                                        	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
                                        	Point operator * (double a) {return Point(x*a,y*a);}
                                        	Point operator / (double a) {return Point(x/a,y/a);}
                                        	double absv() {return sqrt(norm());}
                                        	double norm() {return x*x+y*y;}
                                        	bool operator < (const Point &p) const{
                                        		return x != p.x ? x<p.x: y<p.y;
                                        	}
                                        	bool operator == (const Point &p) const{
                                        		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
                                        	}
                                        };
                                        typedef Point Vector;
                                 #define pl pair<int,pas>
                                        struct Segment{
                                        Point p1,p2;
                                        };
                                         double dot(Vector a,Vector b){
                                        	return a.x*b.x+a.y*b.y;
                                        }
                                        double cross(Vector a,Vector b){
                                        	return a.x*b.y-a.y*b.x;
                                        }
                                    
            bool parareru(Point a,Point b,Point c,Point d){
            //	if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
            	return abs(cross(a-b,d-c))<EPS;
            }
            double distance_ls_p(Point a, Point b, Point c) {
              if ( dot(b-a, c-a) < EPS ) return (c-a).absv();
              if ( dot(a-b, c-b) < EPS ) return (c-b).absv();
              return abs(cross(b-a, c-a)) / (b-a).absv();
            }
            bool is_intersected_ls(Segment a,Segment b) {
            	if(a.p1==b.p1||a.p2==b.p1||a.p1==b.p2||a.p2==b.p2) return false;
            	if(parareru((a.p2),(a.p1),(a.p1),(b.p2))&&parareru((a.p2),(a.p1),(a.p1),(b.p1))){
            //		cout<<"sss"<<endl;
            		if(dot(a.p1-b.p1,a.p1-b.p2)<EPS) return true;
            		if(dot(a.p2-b.p1,a.p2-b.p2)<EPS) return true;
            		if(dot(a.p1-b.p1,a.p2-b.p1)<EPS) return true;
            		if(dot(a.p1-b.p2,a.p2-b.p2)<EPS) return true;
            		return false;
            	}
              else return ( cross(a.p2-a.p1, b.p1-a.p1) * cross(a.p2-a.p1, b.p2-a.p1) < EPS ) && ( cross(b.p2-b.p1, a.p1-b.p1) * cross(b.p2-b.p1, a.p2-b.p1) < EPS );
            }
            double segment_len(Segment a){
            	
            	return (a.p1-a.p2).absv();
            }
            double segment_dis(Segment a,Segment b){
            	if(is_intersected_ls(a,b))return 0;
            	double r=distance_ls_p(a.p1, a.p2, b.p1);
            	r=min(r,distance_ls_p(a.p1, a.p2, b.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p2));
            	r=min(r,distance_ls_p(b.p1, b.p2, a.p1));
            	return r;
            }
            Point intersection_ls(Segment a, Segment b) {
              Point ba = b.p2-b.p1;
              double d1 = abs(cross(ba, a.p1-b.p1));
              double d2 = abs(cross(ba, a.p2-b.p1));
              double t = d1 / (d1 + d2);
             
              return a.p1 + (a.p2-a.p1) * t;
            }
			pair<Point,Point> circle_intersection(Point c1,double r1,Point c2,double r2){
				double d=(c1-c2).absv();
				double h=(r1*r1-r2*r2+d*d)/2.0/d;
				double l=sqrt(r1*r1-h*h);
			//	cout<<d<<" "<<h<<" "<<l<<endl;
				Point asi=c1+(c2-c1)*h/((c2-c1).absv());
				Vector r1r2=(c2-c1)/((c2-c1).absv());
				Vector sui={r1r2.y,-r1r2.x};
			//	cout<<sui.x<<" "<<sui.y<<endl;
				pair<Point,Point> z=mp(asi+sui*l,asi-sui*l);
				if(z.first.x>z.second.x) swap(z.first,z.second);
				return z;
			}
map<string ,int> ma;
int po[50];
bool ok[1<<20]={0};
int an[1<<20]={0};
int dp[1<<20]={0};
bool miok[1<<20]={0};
int dp2[1<<20]={0};
int hi,mi;
vector<int> G[50];
vector<pa> e1,e2,e3;
int ichi[50]={0};


void shoki(int r){
	e1.clear();
	e2.clear();
	e3.clear();
	ma.clear();
	for(int i=0;i<50;i++){
		po[i]=0;
		G[i].clear();
		ichi[i]=0;
	}
	
	for(int i=0;i<(1<<r);i++){
		
		
		dp[i]=0;
		
		dp2[i]=0;
	}
	
}

void makeok(){
	for(int i=0;i<(1<<hi);i++)ok[i]=true;
	
	for(auto t:e1){
		ok[(1<<t.second)+(1<<t.first)]=false;
	}
	
	for(int i=1;i<(1<<hi);i++){
		bool b=ok[i];
		if(b==false) continue;
		for(int j=0;j<hi;j++){
			if(0==(i&(1<<j)))continue;
			if(ok[i-(1<<j)]==false){
				b=false;
				break;
			}
		}
		ok[i]=b;
	}
	return;
	
}
void makean(){
	for(int i=0;i<(1<<hi);i++)an[i]=(1<<(mi))-1;
	
	for(auto t:e3){
		an[(1<<t.first)]^= (1<<(t.second-hi));
	}
	
	for(int i=0;i<(1<<hi);i++){
		
		for(int j=0;j<hi;j++){
			if(0==(i&(1<<j)))continue;
			an[i]=an[1<<j]&an[i-(1<<j)];
		}
	}
	
}

void makedp(){
	for(int i=0;i<(1<<mi);i++)miok[i]=true;
	
	for(auto t:e2){
	
		miok[(1<<t.first)+(1<<t.second)]=false;
	}
	
	for(int i=1;i<(1<<mi);i++){
		bool b=miok[i];
		if(!b) continue;
		miok[i]=true;
		for(int j=0;j<mi;j++){
			if(0==(i&(1<<j)))continue;
			if(miok[i-(1<<j)]==false){
				miok[i]=false;
				break;
			}
		
		}
	}
	for(int i=0;i<(1<<mi);i++)if(miok[i]){
		int cnt=0;
		dp[i]=0;
		for(int  j=0;j<mi;j++)if(i&(1<<j)){
			dp[i]=dp[i-(1<<j)]+po[hi+j];
			break;
		}
		
		
	}
	
	
	
	
	for(int i=0;i<(1<<mi);i++)if(!miok[i]){
		for(int j=0;j<mi;j++){
			if(0==(i&(1<<j)))continue;
			dp[i]=max(dp[i],dp[i-(1<<j)]);
		}
		
	}
}



         signed main(){
int n;
         	while(1){
         	cin>>n;
         		if(n==0) return 0;
         		
         		shoki((n+1)/2);
         	int count1=0;
         	for(int i=0;i<n;i++){
         		string s1,s2;
         		cin>>s1;
         		if(ma.find(s1)==ma.end()){
         			ma[s1]=count1;
         			count1++;
         		}
         		int r3,r4;
         		cin>>r3>>r4;
         		po[ma[s1]]=r3;
         		for(int j=0;j<r4;j++){
         			cin>>s2;
         			if(ma.find(s2)==ma.end()){
         				ma[s2]=count1;
         				count1++;
         			}
         			G[ma[s1]].pb(ma[s2]);
         		}
         	}
         	
         	int n1=n/2;
         	hi=n1,mi=n-n1;
         	for(int i=0;i<G[0].size();i++)ichi[G[0][i]]=1;
         	//for(int i=0;i<n;i++)for(int j=0;j<G[i].size();j++)if(i<G[i][j])cout<<i<<" "<<G[i][j]<<endl;
         	for(int i=0;i<n;i++)for(int j=0;j<G[i].size();j++)if(i<G[i][j]){
         
         	
         		if(G[i][j]<hi) e1.pb(mp(i,G[i][j]));
         		else if(i<hi) e3.pb(mp(i,G[i][j]));
         		else {
         			e2.pb(mp(i-hi,G[i][j]-hi));
         		}
         	}
         	
         	
         //	for(int i=0;i<n;i++)cout<<po[i]<<endl;
    	makeok();
         		
    	makean();
         	
    	makedp();
    	 int ans=0;
 		 for(int i=0;i<(1<<hi);i++)if(ok[i]){
    	
 		 	for(int j=0;j<hi;j++)if(i&(1<<j)){
 		 		
 		 		dp2[i]=dp2[i-(1<<j)]+po[j];
 		 		break;
 		 	}
 		 	if(i&1)ans=max(ans,dp2[i]+dp[an[i]]);
    	}
         		/*
         	int ans=-1;
          for(int i=0;i<(1<<hi);i++)if(ok[i])if(i&1){
          
    		for(int j=0;j<hi;j++)if(i&(1<<j))dp2[i]=max(dp2[i],dp2[i-(1<<j)]);
    		
    		ans=max(ans,dp2[i]+dp[an[i]]);
    		}
         		*/
       
    	cout<<ans<<endl;
         }
           	return 0;
           }


Measured memory_bytes: 29796