#P14103. [ZJCPC 2017] Let's Chat

[ZJCPC 2017] Let's Chat

题目描述

ACM (ACMers' Chatting Messenger) is a famous instant messaging software developed by Marjar Technology Company. To attract more users, Edward, the boss of Marjar Company, has recently added a new feature to the software. The new feature can be described as follows:

If two users, AA and BB, have been sending messages to each other\textbf{each other} on the last mm consecutive\textbf{consecutive} days, the "friendship point" between them will be increased by 11 point.

More formally, if user AA sent messages to user BB on each day between the (im+1)(i-m+1)-th day and the ii-th day (both inclusive), and user BB also sent messages to user AA on each day between the (im+1)(i-m+1)-th day and the ii-th day (also both inclusive), the "friendship point" between AA and BB will be increased by 11 at the end of the ii-th day.

Given the chatting logs of two users AA and BB during nn consecutive days, what's the number of the friendship points between them at the end of the nn-th day (given that the initial friendship point between them is 00)?

输入格式

There are multiple test cases. The first line of input contains an integer TT (1T101 \le T \le 10), indicating the number of test cases. For each test case:

The first line contains four integers nn (1n1091 \le n \le 10^9), mm (1mn1 \le m \le n), xx and yy (1x,y1001 \le x, y \le 100). The meanings of nn and mm are described above, while xx indicates the number of chatting logs about the messages sent by AA to BB, and yy indicates the number of chatting logs about the messages sent by BB to AA.

For the following xx lines, the ii-th line contains two integers la,il_{a,i} and ra,ir_{a,i} (1la,ira,in1 \le l_{a,i} \le r_{a,i} \le n), indicating that AA sent messages to BB on each day between the la,il_{a,i}-th day and the ra,ir_{a,i}-th day (both inclusive).

For the following yy lines, the ii-th line contains two integers lb,il_{b,i} and rb,ir_{b,i} (1lb,irb,in1 \le l_{b,i} \le r_{b,i} \le n), indicating that BB sent messages to AA on each day between the lb,il_{b,i}-th day and the rb,ir_{b,i}-th day (both inclusive).

It is guaranteed that for all 1i<x1 \le i < x, ra,i+1<la,i+1r_{a,i} + 1 < l_{a,i+1} and for all 1i<y1 \le i < y, rb,i+1<lb,i+1r_{b,i} + 1 < l_{b,i+1}.

输出格式

For each test case, output one line containing one integer, indicating the number of friendship points between AA and BB at the end of the nn-th day.

2
10 3 3 2
1 3
5 8
10 10
1 8
10 10
5 3 1 1
1 2
4 5
3
0

提示

For the first test case, user AA and user BB send messages to each other on the 11-st, 22-nd, 33-rd, 55-th, 66-th, 77-th, 88-th and 1010-th day. As m=3m=3, the friendship points between them will be increased by 11 at the end of the 33-rd, 77-th and 88-th day. So the answer is 33.