1
2 2
1 1
1 2
 1
1 3
3
1 2 3
 1
1 1
1000
1000
 1
2 2
2 2
2 2
 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
 1
4 4
1 1 1 1
1 2 3 4
 1
2 3
1 1
1 2 3

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

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        PBDS;

#define int long long
#define endl "\n"
#define MOD 1000000007
#define pb push_back
const int mxN = 1e6 + 500;

int ar[mxN];
int b[mxN];

// taskkill -im A.exe -f
int32_t main() {

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int T;
	cin >> T;
	//T = 1;

	while (T--) {

		int n, m; cin >> n >> m;
		int k = 0;
		bool f = 0, fg = 0;

		vector<int> v;
		set<int> s;

		for (int i = 0; i < n; ++i)
		{
			cin >> ar[i];
		}

		for (int i = 0; i < m; ++i)
		{
			cin >> b[i];
		}
		sort(ar, ar + n);
		sort(b, b + n);

		if (n >= m) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (ar[i] == b[j]) {
						s.insert(ar[i]);
						f = 1;
					}
					if (f == 1)
						break;
				}
			}
		}

		else {
			for (int i = 0; i < m; i++) {
				for (int j = 0; j < n; j++) {
					if (b[i] == ar[j]) {
						s.insert(b[i]);
						f = 1;
					}
					if (fg == 0)
						break;
				}
			}
		}

		if (s.size() == 0) {
			cout << "NO ";
		}
		else {
			cout << "YES\n" << s.size() << " ";
			for (auto x : s) {
				cout << x << " ";
			}
		}

		cout << endl;

	}

	return 0;
}

