#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff;   //譌?剞螟ァ
int N;
map<string, int> m;
bool visit[100000];
char s[10000000];
vector<int> v[100000];
/*
int dfs(int u)
{
	visit[u]=1;
	int ans = 0;
	for(int i=0;i<edge[u].size();i++)
	{
		int v=edge[u][i];
		if(visit[v]==1)
			continue;
		visit[v]=1;
		if(d[v]==1)
			ans+=dfs(v);
		else
			ans+=1;
	}
	return ans;
}
*/
int cnt = 0;

void DFS(int O)
{
    visit[O] = true;

    if( v[O].size() == 0 ) cnt++;
    else
    {
        for(int vi = 0, vn = v[O].size(); vi < vn; vi++)
        {
            if( !visit[v[O][vi] ] ) DFS(v[O][vi] );
        }
    }
}

int main()
{
    while( scanf("%d", &N) )
    {
        if( N == 0 ) break;
        m.clear();

        int clk = 1; cnt = 0;

        fill(visit, visit+100000, false);
        for(int vi = 0; vi < 100000; vi++) v[vi].clear();

        for(int Ni = 0; Ni < N; Ni++)
        {
            scanf("%s", s);
            int sn = strlen(s);

            int gp; string p = "";

            for(int si = 0; si < sn; si++)
            {
                if( s[si] == ':' )
                {
                    if( m[p] == 0 ) m[p] = clk++;
                    gp = m[p]; p = "";
                    clk++;
                }
                else if( s[si] == ',' || s[si] == '.' )
                {
                    if( m[p] == 0 ) m[p] = clk++;
                    v[gp].push_back(m[p] ); p = "";
                }
                else p += s[si];
            }
        }

        DFS(1);
        printf("%d\n", cnt);
    }
}