def dfs(member, group)
  ret = member
  group.each do |g, m|
    if member.include?(g)
      ok = false
      member.delete(g)
      member += m
      ret = dfs(member, group)
    end
  end
  ret
end

while n = gets.to_i
  break if n == 0
  _, member = gets.chomp.delete('.').split(':')
  member = member.split(',')
  group = {}
  (n-1).times do
    g, m = gets.chomp.delete('.').split(':')
    m = m.split(',')
    group[g] = m
  end
  p dfs(member, group).uniq.size
end