CF2148B.Lasers

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Lasers

There is a 2D-coordinate plane that ranges from (0,0)(0,0) to (x,y)(x, y). You are located at (0,0)(0,0) and want to head to (x,y)(x, y).

However, there are nn horizontal lasers, with the ii-th laser continuously spanning (0,ai)(0, a_i) to (x,ai)(x, a_i). Additionally, there are also mm vertical lasers, with the ii-th laser continuously spanning (bi,0)(b_i, 0) to (bi,y)(b_i, y).

You may move in any direction to reach (x,y)(x, y), but your movement must be a continuous curve that lies inside the plane. Every time you cross a vertical or a horizontal laser, it counts as one crossing. Particularly, if you pass through an intersection point between two lasers, it counts as two crossings.

For example, if x=y=2x = y = 2, n=m=1n = m = 1, a=[1]a = [1], b=[1]b = [1], the movement can be as follows:

What is the minimum number of crossings necessary to reach (x,y)(x, y)?

Input

The first line contains tt (1t1041 \leq t \leq 10^4)  — the number of test cases.

The first line of each test case contains four integers nn, mm, xx, and yy ($1 \leq n, m \leq 2 \cdot 10^5, 2 \leq x ,y \leq 10^9$).

The following line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0<ai<y0 \lt a_i \lt y)  — the y-coordinates of the horizontal lasers. It is guaranteed that ai>ai1a_i \gt a_{i-1} for all i>1i \gt 1.

The following line contains mm integers b1,b2,,bmb_1, b_2, \ldots, b_m (0<bi<x0 \lt b_i \lt x)  — the x-coordinates of the vertical lasers. It is guaranteed that bi>bi1b_i \gt b_{i-1} for all i>1i \gt 1.

It is guaranteed that the sum of nn and mm over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output the minimum number of crossings necessary to reach (x,y)(x, y).

Samples

2
1 1 2 2
1
1
2 1 100000 100000
42 58
32
2
3

在线编程 IDE

建议全屏模式获得最佳体验