Accepts: 75
 
 Submissions: 261
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 131072/131072 K (Java/Others)
Problem Description

Long long ago, there were nn adorkable GT. Divided into two groups, they were playing games together, forming a column. The ith GT would randomly get a value of ability bi​​. At the ith second, the ith GT would annihilate GTs who are in front of him, whose group differs from his, and whose value of ability is less than his.

In order to make the game more interesting, GTW, the leader of those GTs, would emit energy for mm times, of which the ith time of emitting energy is ci​​. After the ci​​ second, b1​​,b2​​,...,bci​​​​ would all be added 1.

GTW wanted to know how many GTs would survive after the nth second.

Input

The first line of the input file contains an integerT(5), which indicates the number of test cases.

For each test case, there are n+m+1 lines in the input file.

The first line of each test case contains 2 integers nn and mm, which indicate the number of GTs and the number of emitting energy, respectively.(1n,m50000)

In the following nn lines, the ith line contains two integers ai​​ and bi​​, which indicate the group of the ith GT and his value of ability, respectively. (0ai​​1,1bi​​10^6​​)

In the following mm lines, the ith line contains an integer ci​​, which indicates the time of emitting energy for ith time.

Output

There should be exactly T lines in the output file.

The ith line should contain exactly an integer, which indicates the number of GTs who survive.

Sample Input
1
4 3
0 3
1 2
0 3
1 1
1
3
4
Sample Output
3
Hint
After the first seconds,b1​​=4,b2​​=2,b3​​=3,b4​​=1 After the second seconds,b1​​=4,b2​​=2,b3​​=3,b4​​=1 After the third seconds,b1​​=5,b2​​=3,b3​​=4,b4​​=1,and the second GT is annihilated by the third one. After the fourth seconds,b1​​=6,b2​​=4,b3​​=5,b4​​

相关文章: