#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int n;
vector<string> group;
vector<vector<string> > member;
set<string> ret;

void solve(string s)
{
    int k = find(group.begin(), group.end(), s) - group.begin();
    if(k == n){
        ret.insert(s);
        return;
    }

    for(unsigned i=0; i<member[k].size(); ++i)
        solve(member[k][i]);
    member[k].clear();
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        group.assign(n, "");
        member.assign(n, vector<string>(0));

        for(int i=0; i<n; ++i){
            char c;
            for(;;){
                cin >> c;
                if(c == ':')
                    break;
                group[i] += c;
            }
            string s;
            for(;;){
                cin >> c;
                if(c == '.'){
                    member[i].push_back(s);
                    break;
                }
                if(c == ','){
                    member[i].push_back(s);
                    s.clear();
                }else{
                    s += c;
                }
            }
        }

        ret.clear();
        solve(group[0]);
        cout << ret.size() << endl;
    }
}