#include<iostream>
#include<map>
#include<vector>
#include<string>
using namespace std;

void rec(string s);
int cnt;
map< string, vector<string> >m;
map<string,int>selected;

int main()
{
  int n,i;
  string s,ans;
  string words=":,.",key;
  while(cin>>n,n){
    m.clear();
    ans="";
    while(n-->0){
      cin>>s;
      for(int i=0,start=0;i<s.size();i++){
	if(words.find(s[i])!=string::npos){
	  if(s[i]==':'){
	    key=s.substr(start,i-start);
	  }else{
	    m[key].push_back(s.substr(start,i-start));
	  }
	  if(s[i]=='.')break;
	  start=i+1;
	  if(ans=="")ans=key;
	}
      }
    }
    cnt=0;
    selected.clear();
    rec(ans);
    cout<<cnt<<endl;
  }
}


void rec(string s){
  map< string, vector<string> >::iterator mit;
  vector<string>::iterator vit;
  for(vit=m[s].begin();vit!=m[s].end();vit++){
    if(selected[*vit])continue;
    selected[*vit]=true;
    cnt++;
    if(m.count(*vit)){
      cnt--;
      rec(*vit);
    }
  }
  return;
}