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;
}
相关推荐
你撅嘴真丑3 小时前
第九章-数字三角形
算法
uesowys3 小时前
Apache Spark算法开发指导-One-vs-Rest classifier
人工智能·算法·spark
ValhallaCoder3 小时前
hot100-二叉树I
数据结构·python·算法·二叉树
董董灿是个攻城狮3 小时前
AI 视觉连载1:像素
算法
智驱力人工智能4 小时前
小区高空抛物AI实时预警方案 筑牢社区头顶安全的实践 高空抛物检测 高空抛物监控安装教程 高空抛物误报率优化方案 高空抛物监控案例分享
人工智能·深度学习·opencv·算法·安全·yolo·边缘计算
孞㐑¥4 小时前
算法——BFS
开发语言·c++·经验分享·笔记·算法
月挽清风5 小时前
代码随想录第十五天
数据结构·算法·leetcode
XX風5 小时前
8.1 PFH&&FPFH
图像处理·算法
NEXT065 小时前
前端算法:从 O(n²) 到 O(n),列表转树的极致优化
前端·数据结构·算法
代码游侠6 小时前
学习笔记——设备树基础
linux·运维·开发语言·单片机·算法