B. Lasers

time limit per test

2 seconds

memory limit per test

256 megabytes

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

However, there are n horizontal lasers, with the i-th laser continuously spanning (0,ai) to (x,ai). Additionally, there are also m vertical lasers, with the i-th laser continuously spanning (bi,0) to (bi,y).

You may move in any direction to reach (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=2, n=m=1, a=1, b=1, the movement can be as follows:

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

Input

The first line contains t (1≤t≤104) --- the number of test cases.

The first line of each test case contains four integers n, m, x, and y (1≤n,m≤2⋅105,2≤x,y≤109).

The following line contains n integers a1,a2,...,an (0<ai<y) --- the y-coordinates of the horizontal lasers. It is guaranteed that ai>ai−1 for all i>1.

The following line contains m integers b1,b2,...,bm (0<bi<x) --- the x-coordinates of the vertical lasers. It is guaranteed that bi>bi−1 for all i>1.

It is guaranteed that the sum of n and m over all test cases does not exceed 2⋅105.

Output

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

Example

Input

Copy

复制代码

2

1 1 2 2

1

1

2 1 100000 100000

42 58

32

Output

Copy

复制代码
2
3

解题说明:此题是一道数学题,找规律能发现直接输出m+n即可。

cpp 复制代码
#include <stdio.h>

int main() 
{
	int t, n, m, x, y, a, ans;
	scanf("%d", &t);
	while (t--) 
	{
		scanf("%d %d %d %d", &n, &m, &x, &y);
		ans = n + m;
		while (n--)
		{
			scanf("%d", &a);
		}
		while (m--)
		{
			scanf("%d", &a);
		}
		printf("%d\n", ans);
	}
	return 0;
}
相关推荐
syagain_zsx7 小时前
算法基础篇 · 03 枚举(C++ 题解)
c++·算法·二进制·枚举
weixin_307779137 小时前
C++代码实现MATLAB中的ode23tb函数功能
开发语言·c++·算法·matlab
我是章汕呐8 小时前
地级市能源消耗量及消耗强度数据【2006-2023年】平衡面板
人工智能·经验分享·算法·回归
charliejohn8 小时前
计算机考研 408 数据结构 堆的插入与删除 堆排序
算法
老鱼说AI9 小时前
从点积到希尔伯特空间:向量内积的几何本质与大模型相似度度量
人工智能·深度学习·线性代数·算法·机器学习·数学建模
地平线开发者9 小时前
模型部署|如何解决算子约束
深度学习·算法·自动驾驶
Navigator_Z10 小时前
LeetCode //C - 1254. Number of Closed Islands
c语言·算法·leetcode
deepseek2310 小时前
GPT-6 Astra 破解 FrontierMath 九年悬案拆解:调和熵投票规则反证核恒非空,局部搜索如何终结反例悬赏
人工智能·算法·ai agent
syagain_zsx10 小时前
算法基础篇 · 04 前缀和(C++ 题解)
c++·算法·前缀和
青山是哪个青山12 小时前
LeetCode 123:买卖股票的最佳时机 III
算法