#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

class Group {
public:
    string name;
    vector<string> members;
    Group(){}
    void add(string name) {
        if (find(members.begin(), members.end(), name) == members.end()) {
            members.push_back(name);
        }
    }
    void add(Group g) {
        for (string name: g.members) add(name);
    }
    static Group parse(string s) {
        Group g;
        string t = "";
        for (int i=0; i<(int)s.size(); ++i) {
            if (s[i] == ':') {
                g.name = t;
                t = "";
            } else if (s[i] == ',') {
                g.add(t);
                t = "";
            } else  if (s[i] == '.') {
                g.add(t);
                break;
            } else {
                t += s[i];
            }
        }
        return g;
    }
};

Group expand(map<string, Group> &list, Group g) {
    while (1) {
        bool update = false;
        Group tmp;
        for (string name: g.members) {
            if (list.count(name)) { // グループ名の場合は展開+結合
                tmp.add(list[name]);
                update = true;
            } else {
                tmp.add(name);
            }
        }
        if ( ! update) break;
        g = tmp;
    }
    return g;
}

int main() {
    int n;
    string s;
    while (cin >> n, n) {
        map<string, Group> list;
        cin >> s;
        Group g = Group::parse(s);
        list[g.name] = g;
        Group g1 = g; // first group
        for (int i=1; i<n; ++i) {
            cin >> s;
            Group g = Group::parse(s);
            list[g.name] = g;
        }

        Group t = expand(list, g1);
        cout << (int)t.members.size() << endl;
    }
    return 0;
}
