loop do
  n = gets.to_i
  break if  n == 0
  hash = Hash.new
  input = Array.new
  n.times do |i|
    input[i]=gets.chomp.chop
  end
  n.times do
    n.times do |i|
      tag,names = input[i].split(":")
      members = names.split(",")
      tmp = Array.new
      members.each do |name|
        if hash.has_key?(name)
          hash[name].split(",").each do |str|
          tmp <<  str
        end
        else
          tmp << name
        end
      end
      hash[tag]=tmp.join(",")
    end
  end
  p hash[input[0].split(":")[0]].split(",").uniq.size
end