The Nile runs 6,650 km through ten countries, among them Ethiopia, Sudan and Egypt, before it reaches the Mediterranean. Rain on the highlands of central Africa falls mostly between July and October, and to hold back the yearly floods people built dams along the river, starting with Asyut and Aswan in 1902.
Dams on the same branch change each other's water level whenever one of them stores or releases water, so they have to be operated in step. The African weather observation office predicts the yearly downpours fairly accurately, and the dam keepers sweat over those forecasts while they run the dams. Releasing water every time it rains would do the job, but a dam can hold out for a few days depending on its capacity and a single release is expensive, so deciding when to release and when to store is not easy.

The forecasts are accurate. Write a program that keeps every dam on the branch from overflowing while making the total release cost, meaning the sum of the release costs of all dams, as small as possible.
For example, if dam 1 is given the forecast [t1,t2], dam 1 must release between t1 and t2, and that water must be out in the Mediterranean by t2.
Assume a way to run the dams so that none of them overflows always exists.
Input comes from standard input. The first line holds the number of test cases T (1≤T≤20).
The first line of each test case holds the number of dams N (1≤N≤10). The next N lines describe dams 1 through N, one dam per line. Line i holds the release cost Ci (1≤Ci≤10), the time di (1≤di≤10) the water needs to reach the dam right below, the number of forecasts ki (1≤ki≤10), and then the ki forecasts in order, each written as t1 t2. Dam 1 is the one farthest upstream, and dN is the time the water needs to travel from dam N to the Mediterranean.
All values are integers. Every forecast can be met: each forecast [t1,t2] of dam i satisfies t2−t1≥di+di+1+⋯+dN.
Print to standard output. For each test case print, on a line of its own, the smallest total release cost that keeps every dam from overflowing.