#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
map<string,int> mp;
vector<int> G[1100];
bool vis[1100];
bool isgroup[1100];
int ans;
void dfs(int v){
	vis[v]=1;
	if(!isgroup[v]) ans++;
	for(int u:G[v]) if(!vis[u]) dfs(u);
}
int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0) break;
		mp.clear();
		ans=0;
		rep(i,1100) vis[i]=0,isgroup[i]=0,G[i].clear();
		int I=0;
		rep(i,N){
			string s;
			cin>>s;
			int it=0;
			while(s[it]!=':') it++;
			string g=s.substr(0,it++);
			if(mp.count(g)==0) mp[g]=I++;
			int p=mp[g];
			isgroup[p]=1;
			while(true){
				int it2=it;
				while(islower(s[it2])) it2++;
				string g=s.substr(it,it2-it);
				if(mp.count(g)==0) mp[g]=I++;
				int x=mp[g];
				G[p].pb(x);
				if(s[it2]=='.') break;
				it=it2+1;
			}
		}
		dfs(0);
		cout<<ans<<endl;
	}
}