A. Common Subsequence

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two arrays of integers a1,…,ana1,…,an and b1,…,bmb1,…,bm.

Your task is to find a non-empty array c1,…,ckc1,…,ck that is a subsequence of a1,…,ana1,…,an, and also a subsequence of b1,…,bmb1,…,bm. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.

A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by deletion of several (possibly, zero) elements. For example, [3,1][3,1] is a subsequence of [3,2,1][3,2,1] and [4,3,1][4,3,1], but not a subsequence of [1,3,3,7][1,3,3,7] and [3,10,4][3,10,4].

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000)  — the number of test cases. Next 3t3t lines contain descriptions of test cases.

The first line of each test case contains two integers nn and mm (1≤n,m≤10001≤n,m≤1000)  — the lengths of the two arrays.

The second line of each test case contains nn integers a1,…,ana1,…,an (1≤ai≤10001≤ai≤1000)  — the elements of the first array.

The third line of each test case contains mm integers b1,…,bmb1,…,bm (1≤bi≤10001≤bi≤1000)  — the elements of the second array.

It is guaranteed that the sum of nn and the sum of mm across all test cases does not exceed 10001000 (∑i=1tni,∑i=1tmi≤1000∑i=1tni,∑i=1tmi≤1000).

Output

For each test case, output "YES" if a solution exists, or "NO" otherwise.

If the answer is "YES", on the next line output an integer kk (1≤k≤10001≤k≤1000)  — the length of the array, followed by kk integers c1,…,ckc1,…,ck (1≤ci≤10001≤ci≤1000)  — the elements of the array.

If there are multiple solutions with the smallest possible kk, output any.

Example

input

Copy

5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5

output

Copy

YES
1 4
YES
1 3
NO
YES
1 3
YES
1 2

Note

In the first test case, [4][4] is a subsequence of [10,8,6,4][10,8,6,4] and [1,2,3,4,5][1,2,3,4,5]. This array has length 11, it is the smallest possible length of a subsequence of both aa and bb.

In the third test case, no non-empty subsequences of both [3][3] and [2][2] exist, so the answer is "NO".

 

解题说明:水题,遍历字符串进行判断即可。

#include
int main()
{
	int n, m, i, h, t;
	scanf("%d", &t);
	while(t--)
	{
		scanf("%d %d", &n, &m);
		int a[n+1], b[m+1], f=0;
		for(i=0; i

 

你可能感兴趣的:(AC路漫漫)