### subroutines

def unfold(gname, grps)
  gmems = []

  for mem in grps[gname]
    if grps[mem].nil?
      gmems << mem
    else
      gmems += unfold(mem, grps)
    end
  end
  
  gmems.uniq
end

### main

loop do
  n = gets.to_i
  break if n == 0

  gnames = []
  grps = {}

  n.times do
    gi, mems = gets.strip.delete('.').split(':')
    gnames << gi
    grps[gi] = mems.split(',')
  end
  #p gnames
  #p grps

  puts unfold(gnames.first, grps).length
end