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;
vector<pair<long long, long long> > v;
stack<char> sta;
map<long long, long long> mp, pm;
priority_queue<long long> pq;
set<long long> st;
set<long long>::iterator P;
string s;
long long A[2000001], B[2000001], i, j, n, m, t, k, a, b, c, maxe, mine, sum;
char z;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> t;
  while (t--) {
    k = 0;
    map<long long, long long> mp, pm;
    cin >> n >> m;
    for (i = 0; i < n; i++) cin >> A[i];
    for (i = 0; i < m; i++) cin >> B[i], mp[B[i]]++;
    for (i = 0; i < n; i++)
      if (mp[A[i]]) break;
    if (i == n)
      cout << "NO" << endl;
    else
      cout << "YES" << endl << 1 << " " << A[i] << endl;
  }
  return 0;
}
