#include <bits/stdc++.h>
using namespace std;

map<string, vector<string> > G;
map<string, bool> is_group;
map<string, bool> used;
int N;
int cnt;

void dfs(string s) {
  if ( used[s] ) return;
  used[s] = true;
  if ( is_group[s] ) {
    for ( string t : G[s] ) {
      dfs(t);      
    }
  } else {
    cnt++;
  }
}

int main() {
  while ( cin >> N, N ) {
    string g1 = "";    
    G.clear();
    is_group.clear();
    used.clear();
    cnt = 0;
    for ( int n = 0; n < N; n++ ) {
      string group;
      string s;    
      string t = "";
      cin >> s;      
      for ( int i = 0; i < (int)s.size(); i++ ) {
	if ( s[i] == ':' ) {
	  group = t;
	  is_group[t] = true;	  
	  if ( g1 == "" ) g1 = group;	  
	  t = "";
	} else if ( s[i] == ',' || s[i] == '.' ) {
	  G[group].emplace_back(t);	  
	  t ="";
	} else {
	  t += s[i];	  
	}
      }
    }

    dfs(g1);
    cout << cnt << endl;
  }
  return 0;
}

