import std.stdio;
import std.ascii;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

void main() {
    int N;
    string[][string] M;
    string Q;
    bool input() {
        scanf("%d\n", &N);
        if (N == 0) return false;
        M.clear;
        foreach (_; 0 .. N) {
            string s = readln.chomp.chop;
            auto x = s.split(":");
            string key = x[0];
            if (_ == 0) Q = key;
            string[] value = x[1].split(",");
            M[key] = value;
        }
        return true;
    }
    void solve() {
        bool[string] set;
        bool[string] used;
        void dfs(string key) {
            if (key !in M) {
                set[key] = true;
                return;
            }
            foreach (nkey; M[key]) {
                if (nkey in used) continue;
                used[nkey] = true;
                dfs(nkey);
            }
        }
        dfs(Q);
        writeln(set.length);
    }
    while (input) solve;
}