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>
using namespace std;

#define fastio() ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define ll long long int
#define loop(i,k,n) for(i=k; i<n; i++)
#define trv(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define between(v,x,y) v.begin()+x,v.begin()+y 
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define deb(x) cout<< #x << "=" << x << endl
#define clr(x) memset(x,0,sizeof(x))
#define oparr(v) for(auto x:v) cout << x << " " ; cout << '\n'

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ll> vll;

template<class T> void inp(T& x) {
	cin >> x;
}
template<class H, class... T> void inp(H& h, T&... t) {
	inp(h);
	inp(t...);
}
template<class A> void inp(vector<A>& x) {
	trv(a, x)
		inp(a);
}

const ll mod = 1e9 + 7;

ll lcm(ll a,ll b) { return (a*b)/__gcd(a,b); }

void solve(){
	int i,j;
	int n,m; inp(n,m);
	int res = -1;
	vi a(n),b(m); inp(a); inp(b);
	int cnt[2000];
	loop(i,0,n) cnt[a[i]]++;
	loop(i,0,m){
		if(cnt[b[i]]){
			res = b[i];
			break;
		}
	}
	if(res == -1) cout << "NO\n";
	else{
		cout << "YES\n";
		cout << "1 " << res << '\n';
	}


}	
		
int main(){

	fastio();
    int t = 1;
    inp(t);
    while(t--){
      solve();
    }
 return 0;
}
