import Data.List
import Data.Ord

main = interact $ unlines . map (show . carden_lantern . read') . parse . lines
 where
  parse ("0":_) = []
  parse (_:m:str) = take (read m) str : parse (drop (read m) str)
  read' = map ((\[a,b,d]->((a,b),d)) . map read . splitOn ',')

carden_lantern = count_lantern . cut . reverse . sortBy (comparing snd)
 where
  cut [] = []
  cut (abd@((a,b),d):rs)
   | elem a (map (fst.fst) rs) && elem b (map (snd.fst) rs) =  cut rs
   | otherwise = abd : cut rs
  count_lantern rs = sum $ map ((\d -> div d 100 - 1) . snd) rs

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