main=interact(\f->unlines$map(\x->(\(a:_)(b:_)->unwords[[a],[b],show$sum[1|c<-x,c==a]])x$reverse x)$lines f)