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

int N;
map<string,int> Idx;
set<string> S[100];
vector< vector<string> > V;

void count(int num){
	for(int i=0;i<V[num].size();i++){
		if(Idx[V[num][i]]!=0){
			int id=Idx[V[num][i]]-1;
			if(S[id].empty())
				count(id);
			for(set<string>::iterator it=S[id].begin();it!=S[id].end();it++)
				S[num].insert(*it);
		}
		else S[num].insert(V[num][i]);
	}
}

void solve()
{
	int size=1;
	Idx.clear();
	V.clear();
	V.resize(N);
	for(int i=0;i<100;i++)
		S[i].clear();
	for(int i=0;i<N;i++){
		string now;
		cin>>now;
		for(int j=0;j<now.size();j++)
			if(!islower(now[j])) now[j]=' ';
		istringstream is(now);
		string temp;
		is>>temp;
		Idx[temp]=size++;
		while(is>>temp) V[i].push_back(temp);
	}
	count(0);
	cout<<S[0].size()<<endl;
}

int main()
{
	while(cin>>N){
		if(N==0)
			break;
		solve();
	}
	return 0;
}