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

#define DEBUG(x) cerr << #x << " = " << x << endl

vector<string> splitAll(string s, string t) {
    vector<string> v;
    for(size_t p = 0; (p = s.find(t)) != string::npos; ) {
        v.push_back(s.substr(0, p));
        s = s.substr(p + t.size());
    }
    v.push_back(s);
    return v;
}

int main() {
    for(int N; cin >> N, N; ) {
        vector<pair<string, vector<string> > > vec(N);
        for(int i = 0; i < N; i++) {
            string s; cin >> s;
            s = s.substr(0, s.length() - 1);
            vec[i].first = s.substr(0, s.find(':'));
            s = s.substr(s.find(':') + 1);
            vec[i].second = splitAll(s, ",");
        }
        map<string, int> m;
        for(int i = 0; i < N; i++) {
            if(!m.count(vec[i].first)) {
                int id = m.size();
                m[vec[i].first] = id;
            }
            for(string s : vec[i].second) {
                if(!m.count(s)) {
                    int id = m.size();
                    m[s] = id;
                }
            }
        }
        vector<vector<int> > G(m.size());
        for(auto p : vec) {
            for(string s : p.second) {
                G[m[p.first]].push_back(m[s]);
            }
        }
        int ans = 0;
        queue<int> Q;
        Q.push(m[vec[0].first]);
        vector<char> vis(m.size(), false);
        while(!Q.empty()) {
            int x = Q.front(); Q.pop();
            if(vis[x]) continue;
            vis[x] = true;
            if(G[x].size() == 0) ans++;
            for(int y : G[x]) {
                Q.push(y);
            }
        }
        cout << ans << endl;
    }
}