// Slower C++ solution:
#include <cstdio>

#include <cstring>

#include <string>

#include <queue>

#include <map>

#include <set>

#include <vector>

#include <iostream>

using std::string;

using std::queue;

using std::map;

using std::set;

using std::vector;

int n;

map<string,int> mp;

set<string> st[2010]; 

vector<int> edge[2010];

int in[2010];

char s[100010];

int tot;

string str[2010];

bool init()

{

	memset(in,0,sizeof(in));

	for(int i = 0; i < 2010; i++) edge[i].clear();

	tot = 0; mp.clear();

	scanf("%d",&n);

	if(!n) return false;

	for(int i = 0; i < n; i++)

	{

		scanf("%s",s);

	    string tmp = "";

		int j;

		for(j = 0; s[j]!=':'; j++) tmp += s[j];

		if(mp.find(tmp) == mp.end()) mp[tmp] = tot++,str[tot-1] = tmp;

		int fa = mp[tmp];

		tmp = "";

		for(j++;s[j];j++)

		{

			if(s[j]==',' || s[j] == '.')

			{

				if(mp.find(tmp) == mp.end()) mp[tmp] = tot++,str[tot-1]=tmp;

				edge[mp[tmp]].push_back(fa);

				in[fa]++;

				tmp = "";

			}

			else tmp += s[j];

		}

	}

//	for(int i= 0; i < tot; i++) std::cout<<str[i]<<std::endl;

	return true;

}

void solve()

{

	queue<int> Q;

	for(int i = 0; i < tot; i++) st[i].clear();

	for(int i = 0; i < tot; i++) if(!in[i]) 

	{

	//	printf("i=%d\n",i);

		Q.push(i);

		st[i].insert(str[i]);

	}

	while(!Q.empty())

	{

		int fr = Q.front();Q.pop();

		for(int i = 0; i < edge[fr].size(); i++)

		{

			int to = edge[fr][i];

			--in[to];

			for(set<string>::iterator it = st[fr].begin(); it != st[fr].end(); it++)

			{

				st[to].insert(*it);

			}

			if(!in[to])

			{

				Q.push(to);

			}

		}

	}

	printf("%d\n",st[0].size());

}

int main()

{

	while(init())

		solve();

}

// Faster C++ solution for the same problem (measured speedup: 1.2209781772722554x):
#include<cstdio>

#include<queue>

#include<climits>

#include<iostream>

#include<algorithm>

#include<cstdlib>

#include<cmath>

#include<cstring>

#include<string>

#include<ctype.h>

#include<set>

#include<vector>

#include<map>

#define ff first

#define ss second

using namespace std;

vector <string> a[101];

map<string ,int> m;

map<string ,bool> f;

	string ss,s;

int dfs(int u)  

{  

   int ans = 0;  

   int ll= a[u].size();

   for (int i = 0; i <ll ; i++)  

   {  

       string v = a[u][i];  

       if (f[v] == 1)  

           continue;  

       f[v] = 1;  

       if (m.find(v) != m.end())  

           ans += dfs(m[v]);  

       else  

           ans += 1;    

   }  

   return ans;  

}  

int main()

{

int i,j,T,N,S,W,Q;

while (scanf("%d",&N)&&N)

{



	m.clear();f.clear();

	for (i=0;i<N;i++)

	{

		a[i].clear();

		cin>>ss;  

           bool ff = 1,o=0;

		   int   en,k=0;  

           while (ff)  

           {  

               if (!o)  

                   en = ss.find(':', k);  

               else  

               {  

                   en = ss.find(',', k);  

                   if (en == -1)  

                       {en = ss.size() - 1;ff=0;} 

               }  

               s.assign (ss,k, en - k);

//               cout<<"@"<<s;

				k=en+1;

			if (!o){

				o=1;

				m[s]=i;

				f[s]=0;

			}

			else

			{

				a[i].push_back(s); 

				f[s]=0;

			}

           }  

		/*

		a[i].clear() ;

		string s;

		scanf("%s",ss);

		j=0;

		while (ss[j]!=':') j++;

		ss[j]='\0';

		s=ss;

		m[s]=i;f[s]=0;

		bool ff=1;

		while (ff)

		{

		j++;

		T=j;

		while (ss[j]!=','&&ss[j]!='.') j++;

		if (ss[j]=='.') ff=0;

		ss[j]='\0';

		s=(ss+T);

		f[s]=0;

		a[i].push_back(s);

		

		}*/

	}

    printf("%d\n",dfs(0));

}

}

//freopen("video.in","r",stdin);

//freopen("video.out","w",stdout);