Limits 2s, 512 MB

Congratulations on becoming the new boss of "Horizontal Company, branch: Sylhet"! But now you have a hard task in front of you, The central branch has sent you a list of MM prospective employees to put in your office. However, just like it's name, the company's office is a long horizontal continuous segment [0,N][0, N]. Each employee has a specific coordinate XX where he will work, along with a radius RR of workspace. i.e. any point <R< R distance from X is used by that employee for work (points at exactly R distance are not used). Formally speaking, consider any coordinate YY (not necessarily integer), if YX<R|Y-X| < R then this point is used by the employee. Being an efficient boss, you want to select the maximum number of employees such that their workspaces don't intersect.

But there's another problem! This branch is relatively new, so the whole office is not really open yet. The central office will give you a segment [L,R][L, R] to work with. The workspaces of the selected employees should be strictly inside the given segment. The central office has sent you QQ emails each containing a segment [L,R][L, R]. You need to tell them what is the maximum number of employees you can select for each such segment. Note that each segment is independent from other emailed segments.

Input

First line will contain number of test cases, TT (1T101 \le T \le 10). Each test case will be an independent office (and staff). Each test case will begin with a line containing NN (1N1091 \le N \le 10^9) and MM (1M1051 \le M \le 10^5). Next MM lines will contain two numbers, XX (0XN0 \le X \le N) and RR (1R<N1 \le R < N), the employee's working coordinate and radius of work. Next line will contain QQ (1Q1051 \le Q \le 10^5). Next QQ lines will contain LL and RR (0L<RN0 \le L < R \le N).

Output

For each test case, first output "Case #:" in a single line. Then for each of the emailed segments [L,R][L, R] in that case, output a line containing the maximum number of employees you can select for that segment.

Sample

InputOutput
2
20 3
5 5
15 5
10 10
1
0 20
20 3
5 5
15 5
10 5
2
3 17
10 15
Case 1:
2
Case 2:
1
0

In the first case, employee no 1 and 2 can be selected who cover the intervals (0,10)(0, 10) and (10,20)(10, 20).

In the second case, for first email, employee no 3 can be selected who covers (5,15)(5, 15) interval. For second email no employee can be chosen, as their intervals (0,10)(0, 10), (10,20)(10, 20) and (5,15)(5, 15) do not fit inside (10,15)(10, 15).


Submit

Login to submit.

Statistics

50% Solution Ratio
rebornEarliest, Oct '19
ash_98Fastest, 1.3s
nusuBotLightest, 27 MB
ash_98Shortest, 2598B
Toph uses cookies. By continuing you agree to our Cookie Policy.