#include <stdio.h>
#include <string.h>
#define NUM 1510
int n, cnt;
char s[NUM][100];
int g[NUM][NUM], size[NUM], group[NUM], gnum;
int vis[NUM];
int stk[NUM], top;

void get()
{
    int i, j;
    char c = getchar();
    while(c == ' ' || c == '\n') c = getchar();
    char tmp[100];
    int num = 0;
    do
    {
        tmp[num++] = c;
        c = getchar();
    }
    while(c != ':');
    for(i = 0; i < cnt; i++)
    {
        for(j = 0; j < num; j++)
            if(tmp[j] != s[i][j])
                break;
        if(j == num)
            break;
    }
    if(i == cnt)
    {
        for(j = 0; j < num; j++)
            s[i][j] = tmp[j];
        cnt++;
    }
    int u = i;
    group[gnum++] = u;
    do
    {
        c = getchar();
        num = 0;
        do
        {
            tmp[num++] = c;
            c = getchar();
        }
        while(c != ',' && c != '.');
        for(i = 0; i < cnt; i++)
        {
            for(j = 0; j < num; j++)
                if(tmp[j] != s[i][j])
                    break;
            if(j == num)
                break;
        }
        if(i == cnt)
        {
            for(j = 0; j < num; j++)
                s[i][j] = tmp[j];
            cnt++;
        }
        g[u][size[u]++] = i;
        //cout << tmp << ',';
    }
    while(c != '.');
    //cout << endl;
}

int main()
{
    int i, j = 0, u;
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
#endif
    while(~scanf("%d", &n) && n)
    {
        memset(size, 0, sizeof(size));
        memset(g, 0, sizeof(g));
        memset(group, 0, sizeof(group));
        memset(vis, 0, sizeof(vis));
        gnum = 0;
        cnt = 0;
        for(i = 0; i < n; i++)
            get();
        vis[0] = 1;
        top = 0;
        stk[top++] = 0;
        while(top > 0)
        {
            u = stk[--top];
            for(i = 0; i < size[u]; i++)
                if(!vis[g[u][i]])
                {
                    vis[g[u][i]] = 1;
                    stk[top++] = g[u][i];
                }
        }
        for(i = 0; i < gnum; i++)
            vis[group[i]] = 0;
        int ans = 0;
        //cout << cnt << endl;
        for(i = 0; i < cnt; i++)
            if(vis[i])
                ans++;
        if(j)
            printf("\n");
        printf("%d", ans);
        j++;
    }
    return 0;
}