#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
// const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (40 + 2)
#define SIZE_PER_ONCE 20

const ull ONE = 1;

// 国の集合の中の総和の最大
ull dp[2][1 << SIZE_PER_ONCE];

map<string, int> name2index;
vector<string> tmp_neighbor[MAX_N];
int power[MAX_N];
ull neighbor[MAX_N];

void set_dp(int dp_index, int start_index, int size) {
  for (int i = 1; i < (1 << size); i++){
    ull b = 0;
    ull score = 0;
    for (int j = 0; j < size; j++){
      if ((i & (1 << j)) == 0) {
        continue;
      }
      if ((b & neighbor[start_index + j]) != 0) {
        score = 0;
        break;
      }
      score += power[start_index + j];
      b |= ONE << (start_index + j);
    }
    dp[dp_index][i] = score;
  }

  if (start_index == 0) {
    return;
  }

  // 高速メビウス変換で最大値を出す
  for(int i=0; i<size; i++) {
    for(int s=0; s<(1<<size); s++) {
      if ((s>>i&1)==1) {
        dp[dp_index][s]= max(dp[dp_index][s^(1<<i)], dp[dp_index][s]);
      }
    }
  }

}

void init() {
  for (int i = 0; i < MAX_N; i++){
      tmp_neighbor[i].clear();
  }

  name2index.clear();
}

void exec(int n){
  string a;
  int b, c;
  string s;

  init();

  for (int i = 0; i < n; i++){
    cin >> a;
    scanf("%d%d", &b, &c);
    name2index[a] = i;
    power[i] = b;

    for (int j = 0; j < c; j++){
      cin >> s;
      // printf("|tmp_neighbor[%d]| = %d\n", i, tmp_neighbor[i].size());
      tmp_neighbor[i].push_back(s);
    }
  }

  for (int i = 0; i < n; i++){
    ull tmp = 0;
    tmp |= ONE << i;

    for (int j = 0; j < tmp_neighbor[i].size(); j++){
      tmp |= ONE << name2index[tmp_neighbor[i][j]];
    }
    // printf("neighbor[%d] = %lld\n", i, tmp);
    // cout << static_cast<std::bitset<8> >(tmp) << endl;

    neighbor[i] = tmp;
  }

  ull ans = 0;
  if (n <= SIZE_PER_ONCE) {
    set_dp(0, 0, n);

    for (int i = 0; i < (ONE << n); i++){
      if ((i & 1) == 1) {
    // cout << static_cast<std::bitset<16> >(i) << endl;
        ans = max(ans, dp[0][i]);
      }
    }
  }
  else {
    // 前半分を計算
    set_dp(0, 0, SIZE_PER_ONCE);
    // 前半分を計算
    set_dp(1, SIZE_PER_ONCE, n - SIZE_PER_ONCE);

    for (int i = 0; i < (ONE << SIZE_PER_ONCE); i++){
      if ((i & 1) == 1) {
        ull tmp = dp[0][i];

        ull tmp_mask = 0, mask = 0;
        for (int j = 0; j < SIZE_PER_ONCE; j++){
          if (((i >> j) & 1) == 1) {
            tmp_mask |= neighbor[j];
          }
        }
        tmp_mask >>= SIZE_PER_ONCE;

        for (int j = 0; j < n - SIZE_PER_ONCE; j++){
          if (((tmp_mask >> j) & 1) == 0) {
            mask |= ONE << j;
          }
        }
        tmp += dp[1][mask];

        ans = max(tmp, ans);
      }
    }
  }

  cout << ans << endl;
}

void solve(){
  int t = 1;
  while (scanf("%d", &t) != EOF) {
    if (t == 0) {
      break;
    }
    exec(t);
  }
}

int main(){
  solve();
  return 0;
}



Measured memory_bytes: 19756