#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> pii;

void parse(string in, string& group, vector<string>& mem) {
	int k=0;
	while(in[k]!=':') k++;
	group = in.substr(0,k);
	k++;
	string name = "";
	while(k < in.length()) {
		if(in[k]==',' || in[k]=='.') {
			mem.push_back(name);
			name = "";
		} else {
			name += in[k];
		}
		k++;
	}
}

typedef pair<int, vector<string> > pivs;
map< string, pivs > graph;
bool visit[101];

void dfs(string p) {
	if( graph.find(p) == graph.end() ) return;
	if( visit[graph[p].first] ) return;
	visit[ graph[p].first ] = true;
	for(int i=0; i<graph[p].second.size(); i++) {
		string s = graph[p].second[i];
		dfs(s);
	}
}

int main() {
	int n;
	while(cin >> n, n) {
		memset(visit, 0, sizeof(visit));
		graph.clear();
		vector<string> in(n);
		string fs;
		rep(i,n) {
			cin >> in[i];
			string g;
			vector<string> m;
			parse(in[i], g, m);
			graph[g] = pivs(i, m);
			if(i==0) fs = g;
		}

		dfs(fs);
		vector<string> _in;
		rep(i, n) {
			if(visit[i]) {
				_in.push_back(in[i]);
			}
		}
		in = _in;

		set<string> gr, em;
		rep(i, in.size()) {
			string g;
			vector<string> m;
			parse(in[i], g, m);
			gr.insert(g);
			rep(j, m.size()) em.insert(m[j]);
		}
		vector<string> s;
		set_difference(em.begin(), em.end(), gr.begin(), gr.end(), back_inserter(s));
		cout << s.size() << endl;
	}
	return 0;
}