#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

int exibit[1 << 20];
void init() {
	rep1(i, (1 << 20) - 1) {
		rep(j, 20)if (i&(1 << j)) {
			exibit[i] = j; break;
		}
	}
}

int n;
void solve() {
	map<string, int> mp;
	map<string, bool> used;
	vector<vector<bool>> b(n);
	rep(i, n)b[i].resize(n, false);
	int cur = 0;
	vector<int> c(n);
	vector<bool> ban(n, false);
	rep(i, n) {
		string s; cin >> s;
		if (!used[s]) {
			used[s] = true;
			mp[s] = cur; cur++;
		}
		int id = mp[s];
		cin >> c[id];
		int d; cin >> d;
		rep(j, d) {
			string st; cin >> st;
			if (!used[st]) {
				used[st] = true;
				mp[st] = cur; cur++;
			}
			int to = mp[st];
			if (i == 0)ban[to] = true;
			b[id][to] = b[to][id] = true;
		}
	}
	ban[0] = true;
	vector<int> v;
	rep(i, n)if (!ban[i])v.push_back(i);
	int ans = 0;
	int len = v.size();
	int d1 = len / 2; int d2 = len - d1;
	vector<int> memo(1 << d2, 0);
	vector<bool> pass(1 << d2,false);
	rep(i, (1 << d2)) {
		if (pass[i]) {
			rep(j, d2) {
				pass[i | (1 << j)] = true;
			}
			continue;
		}
		vector<int> u;
		rep(j, d2) {
			if (i&(1 << j))u.push_back(v[j + d1]);
		}
		bool f = true;
		if (i>0&&u.size()<3) {
			int chk = exibit[i];
			rep(j, d2) {
				if (i & (1 << j)) {
					if (b[v[chk + d1]][v[j + d1]]) {
						f = false; break;
					}
				}
			}
		}
		if (!f) {
			rep(j, d2) {
				if ((i&(1 << j))==0) {
					pass[i^(1<<j)] = true;
				}
			}
			continue;
		}
		rep(j, u.size())memo[i] += c[u[j]];
	}
	rep(i, (1 << d2)) {
		rep(j, d2) {
			if (i&(1 << j)) {
				memo[i] = max(memo[i], memo[i^(1<<j)]);
			}
		}
	}
	fill(pass.begin(), pass.begin() + (1 << d1), false);
	vector<int> trans(1 << d1, (1 << d2) - 1);
	rep1(i, (1 << d1) - 1) {
		int chk = exibit[i];
		int mem = 0;
		rep(j, d2) {
			if (b[v[chk]][v[d1 + j]])mem += (1 << j);
		}
		mem = (1 << d2) - 1 - mem;
		trans[i] = trans[i^(1<<chk)] & mem;
	}
	rep(i, (1 << d1)) {
		if (pass[i]) {
			rep(j, d1) {
				pass[i | (1 << j)] = true;
			}
			continue;
		}
		vector<int> u;
		rep(j, d1) {
			if (i&(1 << j))u.push_back(v[j]);
		}
		bool f = true;
		if (i>0&&u.size()<3) {
			int chk = exibit[i];
			rep(j, d1) {
				if (i & (1 << j)){
					if (b[v[chk]][v[j]]) {
						f = false; break;
					}
				}
			}
		}
		if (!f) {
			rep(j, d1) {
				if ((i&(1 << j)) == 0) {
					pass[i^(1<<j)] = true;
				}
			}
			continue;
		}
		int sum = 0;
		rep(j, u.size()) {
			sum += c[u[j]];
		}
		ans = max(ans, sum + memo[trans[i]]);
	}
	cout << ans + c[0] << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	init();
	while (cin >> n, n) {
		solve();
	}
	//solve();
	//stop
	return 0;
}


Measured memory_bytes: 13608