def fold arr
    arr2 = []
    arr.each{|name|
        if @h.key? name
            @h[name] = fold(@h[name])
            @h[name].each{|name2| arr2 << name2}
        else
            arr2 << name
        end
    }
    arr2.uniq!
    arr2
end

while true
    n = gets.to_i
    break if n == 0
    @h = Hash.new{|h, k| h[k] = []}
    firstgroup = nil
    n.times{|i|
        group, members = (gets.chomp)[0..-2].split(":")
        members = members.split(",")
        @h[group] = members
        firstgroup = group if i == 0
    }
    puts fold(@h[firstgroup]).length
end
