// 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.2239948944860015x):
#include <stdio.h>    

#include <string.h>    

#include <set>  

#include <map>  

#include <algorithm>  

#include <iostream>  

#include <vector>  

#include <string>  

#include <cmath>  

template <class T>

inline bool rd(T &ret) {

	char c; int sgn;

	if (c = getchar(), c == EOF) return 0;

	while (c != '-' && (c<'0' || c>'9')) c = getchar();

	sgn = (c == '-') ? -1 : 1;

	ret = (c == '-') ? 0 : (c - '0');

	while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');

	ret *= sgn;

	return 1;

}

template <class T>

inline void pt(T x) {

	if (x <0) {

		putchar('-');

		x = -x;

	}

	if (x>9) pt(x / 10);

	putchar(x % 10 + '0');

}

using namespace std;

const int N = 3000 + 105;



int n, m;

vector<string> myset[105];

set<string>ans;

map<string, int> mp;

string s;

bool vis[105];

void dfs(int x){

	vis[x] = 1;

	for (int i = 0; i < myset[x].size(); i++)

	{

		if (mp.count(myset[x][i]))

		{

			if (!vis[mp[myset[x][i]]])

			dfs(mp[myset[x][i]]);

		}

		else ans.insert(myset[x][i]);

	}

}

string str;

int main(){

	while (cin>>n, n){

		memset(vis, 0, sizeof vis);

		mp.clear();

		for (int j = 1; j <= n; j++){

			cin >> str; str[str.length() - 1] = ',';

			int pos = str.find(':');

			string temp = str.substr(0, pos);

			mp[temp] = j;

			while (1)

			{

				str = str.substr(pos + 1);

				pos = str.find(',');

				if (pos == -1)	break;

				temp = str.substr(0, pos);

				myset[j].push_back(temp);

			}

			sort(myset[j].begin(), myset[j].end());

			myset[j].erase(unique(myset[j].begin(), myset[j].end()), myset[j].end());

		}

		ans.clear();

		dfs(1);

		pt((int)ans.size()); puts("");

		for (int j = 1; j <= n; j++)myset[j].clear();

	}

	return 0;

}