import Data.Ord
import Data.List

main = interact $ unlines . map (show . carden_lantern) . read' . lines
 where
  read' ("0":_) = []
  read' (_:m:xs) = map (parse . map read . splitOn ',') edge : read' xs'
   where
    (edge,xs') = splitAt (read m) xs
    parse [a,b,d] = ((a,b), div d 100)

carden_lantern = count . foldl' foldpath [] . sortBy (comparing snd)
 where
  count abd =  sum (map snd abd) - length abd
  foldpath acc abd@((a,b),_) = if disjoint a b (map fst acc) then (abd:acc) else acc
  disjoint a b ab
   | null ab = True
   | a == b = False
   | otherwise = and $ map (\(_,a') -> disjoint a' b (tail ab)) (filter ((==a).fst) ab)

splitOn c xs
 | null xs = []
 | head xs == c = splitOn c (tail xs)
 | otherwise = (takeWhile (/= c)) xs : splitOn c (dropWhile (/= c) xs)