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;
}
相关推荐
vortex53 分钟前
几种 dump hash 方式对比分析
算法·哈希算法
Wei&Yan1 小时前
数据结构——顺序表(静/动态代码实现)
数据结构·c++·算法·visual studio code
团子的二进制世界2 小时前
G1垃圾收集器是如何工作的?
java·jvm·算法
吃杠碰小鸡2 小时前
高中数学-数列-导数证明
前端·数学·算法
故事不长丨2 小时前
C#线程同步:lock、Monitor、Mutex原理+用法+实战全解析
开发语言·算法·c#
long3162 小时前
Aho-Corasick 模式搜索算法
java·数据结构·spring boot·后端·算法·排序算法
近津薪荼2 小时前
dfs专题4——二叉树的深搜(验证二叉搜索树)
c++·学习·算法·深度优先
熊文豪2 小时前
探索CANN ops-nn:高性能哈希算子技术解读
算法·哈希算法·cann
熊猫_豆豆2 小时前
YOLOP车道检测
人工智能·python·算法
艾莉丝努力练剑2 小时前
【Linux:文件】Ext系列文件系统(初阶)
大数据·linux·运维·服务器·c++·人工智能·算法