#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <bitset>

#define FOR(i, a, b) for(int i = (int)a; i < (int)b; ++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
template <class T, class U> void CHMAX(T & a, const U & b) { if (a < b) a = b; }
template <class T, class U> void CHMIN(T& a, const U& b) { if (a > b) a = b; }

using B = long long;
B g[41];
bool ok1[1 << 21];
bool ok2[1 << 21];
int set[1 << 21];
int dp[1 << 21];
int cost1[1 << 21];
int cost2[1 << 21];

class MaxIndependentSet { // V = V1 \cup V2
	int n, n1, n2;
	//std::vector<B> g;
	//std::vector<bool> ok1, ok2; // ok[S] : Is S\subseteq V stable?
	//std::vector<B> set; // set[S] : node-set \subseteq V2 which not adjacent to S
	//std::vector<int> dp; // dp[S] : max independent set in S \subseteq V2
	//std::vector<int> cost1, cost2; // cost[S] : cost S

public:
	MaxIndependentSet(const std::vector<std::vector<int>>& g_) { setG(g_); }

	void setG(const std::vector<std::vector<int>>& g_) {
		n = g_.size();
		n1 = n / 2;
		n2 = n - n1;
		REP(i, n) g[i] = 0ll;
		for (int i = 0; i < n; ++i) {
			for (auto& to : g_[i]) {
				g[i] |= 1ll << to;
				g[to] |= 1ll << i;
			}
		}
	}

	int calc(std::vector<int> s) {
		{ // ok1
			REP(i, 1 << n1) ok1[i] = true;
			REP(i, n1) FOR(j, i + 1, n1) if (g[i] & 1 << j) ok1[1 << i ^ 1 << j] = false;

			REP(bit, 1 << n1) {
				if (!ok1[bit]) continue;
				int tbit = bit;
				while (tbit) {
					int i = tbit & -tbit;
					if (!ok1[bit ^ i]) {
						ok1[bit] = false;
						break;
					}
					tbit ^= i;
				}
			}
		}
		{ // ok2
			REP(i, 1 << n2) ok2[i] = true;
			REP(i, n2) FOR(j, i + 1, n2) if (g[i + n1] >> n1 & 1 << j) ok2[1 << i ^ 1 << j] = false;

			REP(bit, 1 << n2) {
				if (!ok2[bit]) continue;
				int tbit = bit;
				while (tbit) {
					int i = tbit & -tbit;
					if (!ok2[bit ^ i]) {
						ok2[bit] = false;
						break;
					}
					tbit ^= i;
				}
			}
		}

		{ // set
			REP(i, 1 << n1) set[i] = (1 << n2) - 1;
			REP(i, n1) set[1 << i] &= ~g[i] >> n1;

			REP(bit, 1 << n1) {
				int tbit = ~bit & ((1 << n1) - 1);
				while (tbit) {
					int i = tbit & -tbit;
					set[bit | i] = set[bit] & set[i];
					tbit ^= i;
				}
			}
		}

		{ // cost1
			REP(bit, 1 << n1) {
				cost1[bit] = 0;
				REP(i, n1) if (bit & 1 << i) cost1[bit] += s[i];
			}
		}
		{ // cost2
			REP(bit, 1 << n2) {
				cost2[bit] = 0;
				REP(i, n2) if (bit & 1 << i) cost2[bit] += s[i + n1];
			}
		}

		{ // dp
			REP(i, 1 << n2) dp[i] = 0;
			REP(bit, 1 << n2) if (ok2[bit]) dp[bit] = cost2[bit];

			REP(bit, 1 << n2) {
				int tbit = ~bit & ((1 << n2) - 1);
				while (tbit) {
					int i = tbit & -tbit;
					dp[bit | i] = std::max(dp[bit | i], dp[bit]);
					tbit ^= i;
				}
			}
		}

		int res = 0;
		REP(bit, 1 << n1) {
			if (!ok1[bit]) continue;
			res = std::max(res, cost1[bit] + dp[set[bit]]);
		}
		return res;
	}
};

signed main() {
	MaxIndependentSet mis({});

	int n;
	while (std::cin >> n, n) {
		std::vector<int> s(n); // strength
		std::vector<std::vector<int>> g;
		{
			std::unordered_map<std::string, int> map;
			std::vector<std::string> a(n);
			std::vector<int> b(n);
			std::vector<std::vector<std::string>> d(n);

			REP(i, n) {
				int sz = -1;
				std::cin >> a[i] >> b[i] >> sz;
				map[a[i]];
				d[i].reserve(sz);
				REP(_, sz) {
					std::string t;
					std::cin >> t;
					d[i].emplace_back(t);
				}
			}

			int p = 0;
			for (auto& e : map) e.second = p++;
			g.resize(p);

			REP(i, n) {
				int idx = map[a[i]];
				s[idx] = b[i];
				for (auto& t : d[i]) g[idx].emplace_back(map[t]);
			}
			for (auto& t : d[0]) s[map[t]] = -10000000;
		}

		mis.setG(g);
		std::cout << mis.calc(s) << std::endl;
	}

	return 0;
}


Measured memory_bytes: 21812