require 'set'

def f(groups, g_name)
	s = 0
	subgroups, members = groups[g_name]
	subgroups.each{|sg| s |= f(groups, sg)}
	s |= members
	s
end

loop {
	n = gets.to_i
	break if n == 0
	groups = {}
	n.times {
		name, *members = gets.chomp.split(/[:,.]/)
		groups[name] = members
	}

	m_index = {}
	groups.each{|name, members|
		groups[name] = members.partition{|m| groups[m]}.map{|a| Set[*a]}
		groups[name][1].map!{|m|
			m_index[m] ||= m_index.size
			1 << m_index[m]
		}
		groups[name][1] = groups[name][1].inject(0, :|)
	}
	p f(groups, groups.to_a[0][0]).to_s(2).count(?1)
}