Long long ago, there is a gold mine.The mine consist of many layout, so some area is easy to dig, but some is very hard to dig.To dig one gold, we should cost some value and then gain some value. There are many area that have gold, because of the layout, if one people want to dig one gold in some layout, he must dig some gold on some layout that above this gold's layout. A gold seeker come here to dig gold.The question is how much value the gold he can dig, suppose he have infinite money in the begin.
First line the case number.(<=10)
Then for every case:
one line for layout number.(<=100)
for every layout
first line gold number(<=25)
then one line for the dig cost and the gold value(32bit integer), the related gold number that must be digged first(<=50)
then w lines descripte the related gold followed, each line two number, one layout num, one for the order in that layout
see sample for details
Case #x: y.
x for case number, count from 1.
y for the answer.
10 100 0
10 100 1
10 100 1
Case #1: 270