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

using ll=long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define ALL(v) v.begin(),v.end()

string buf="";
string s="";

void dfs(ll pos, vector<vector<ll>>& adj, vector<bool>& used,set<ll>& leaf) {
	used[pos]=true;
	if((ll)adj[pos].size()==0)  {
		leaf.insert(pos);
		return;
	}
	REP(i,(ll)adj[pos].size()) {
		if(!used[adj[pos][i]]) dfs(adj[pos][i],adj,used,leaf);
	}
	return;
}

int main(){
	while(1) {
		ll n;
		cin>>n;
		if(n==0) break;
		ll cnt=0;
		vector<string> sp;	
		map<string,ll> dict;
		vector<vector<ll>> adj(2000);
		REP(i,n) {
			cin>>s;
			buf="";
			vector<string> used;
			REP(j,(ll)s.length()) {
				if(s[j]==':') {
					sp.push_back(buf);
					used.push_back(buf);
					if(dict.count(buf)==0) {
						dict[buf]=cnt;
						cnt++;
					}
					buf="";
				} else if(s[j]==','||s[j]=='.') {
					used.push_back(buf);
					if(dict.count(buf)==0) {
						dict[buf]=cnt;
						cnt++;
					}
					buf="";
				} else buf+=s[j];
			}
			for(ll j=1; j<(ll)used.size(); j++) {
				adj[dict[used[0]]].push_back(dict[used[j]]);
			}
		}
		for(auto x:dict) {
			//cout<<"piyo"<<x.first<<" "<<x.second<<endl;
		}
		set<ll> leaf;
		vector<bool> used(2000,false);
		dfs(dict[sp[0]],adj,used,leaf);
		cout<<(ll)leaf.size()<<endl;
	}	
	return 0;
}
