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;
}
相关推荐
小O的算法实验室3 小时前
IEEE TASE,基于MPC的多无人机协同搜索竞争群体优化方法
算法
Tbisnic4 小时前
BGE-M3 算法详解:从模型架构到三种检索方式的数学原理
算法·自然语言处理·大模型·bert·transformer·注意力机制
Brilliantwxx4 小时前
【算法从零到千】【55-58】哈希位图+常见数学运算 接口
算法
空堂与归5 小时前
用户分群找不到规律?用K-Means聚类算法自动发现数据模式
算法·机器学习·kmeans·聚类
动词ing5 小时前
【C语言】自定义函数+指针入门
c语言·开发语言·算法
重生之后端学习6 小时前
283. 移动零[简单]✅
开发语言·数据结构·算法·leetcode·职场和发展
一只小小的芙厨6 小时前
基础数论总结
笔记·学习·算法
夜不会漫长7 小时前
C++入门(1)
开发语言·c++·算法
wen_zhufeng8 小时前
IndexTTS 2.5 技术报告
人工智能·算法·机器学习
大熊背9 小时前
树莓派相机自动白平衡详解(四)
算法·树莓派·白平衡·isppipeline