GNTFNTN - Giant fountain

no tags 

The Dystopian government has installed a giant fountain in front of the parliament building. The fountain consists of N levels stacked one on top of the other and is situated on top of a large tank of infinite capacity. The levels of the fountain are numbered 1 to N from top to bottom. The top l1 levels are identical with capacity c1, the next l2 levels identical with capacity c2,... the final lK levels with capacity cK. Here l1 + l2 + ... lK = N.

When water is added to level i beyond its capacity, the excess water overflows to level i+1. Water overflowing from level N is collected in the tank. Water is added to the levels in the following fashion. First, w1 amount of water is added to each level i such that s1 ≤ i ≤ e1. Then w2 amount of water is added to each s2 ≤ i ≤ e2... Finally wM amount is added to sM ≤ i ≤ eM. Note that water might be added to the same level multiple times in this fashion. You have to find out the amount of water that has overflowed to the tank at the bottom, and the total number of levels of the fountain that are completely filled

Input

The first line of the input contains T (≤10), the number of test cases. Following this are the descriptions of the test cases.

The first line of the description of a test case contains space separated integers N (≤2x108), K (≤2000) and M (≤104). Following this are K lines, each containing a space separated pair of integers. These are the (li,ci) pair as explained in the problem statement. Here l1 + l2 + ... lK = N and ci ≤ 108. This is followed by M lines, each containing a space separated triplet of integers. These are (si,ei,wi) as explained in the problem statement. 1 ≤ si ≤ ei ≤ N and wi ≤ 106

Output

For each test case output a space separated pair of integers : The total amount of water that has overflowed to the tank and the number of levels of the fountain that are completely filled.

Example

Input:
1
10 2 1
5 6
5 3
3 9 5

Output:
5 5

hide comments
:D: 2012-11-06 11:27:07

Sorry, but I find the description very clear and easy to read. There's nothing to clarify.

dark passenger: 2011-03-23 11:51:41

description is very poor .....
Those who have solved please try to simplify the meaning....
Thank You


Added by:Raziman T V
Date:2011-02-13
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:IOPC2011