def find(x, root)
  return unless @group[x]
  return true if @group[x].include?(root)
  @group[x].each do |m|
    return true if find(m, root)
  end
  false
end

while n = gets.to_i
  break if n == 0
  root = ''
  @group = {}
  n.times do |i|
    g, m = gets.split(':')
    root = g if i == 0
    ms = m[0..-3].split(',')
    ms.each{ |m| @group[m] ||= []; @group[m] << g }
  end
  cnt = 0
  @group.keys.each do |name|
    if find(name, root) && !@group.values.flatten.include?(name)
      cnt += 1
    end
  end
  p cnt
end