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;
int main() {
  int t, m, n, a[1000], b[1000], mi, ni, f, v;
  cin >> t;
  while (t) {
    cin >> m >> n;
    mi = 0;
    ni = 0;
    while (mi < m) {
      cin >> a[mi];
      mi++;
    }
    while (ni < n) {
      cin >> b[ni];
      ni++;
    }
    mi = 0;
    ni = 0;
    v = 0;
    while (mi < m && v == 0) {
      while (ni < n && v == 0) {
        if (a[mi] == b[ni]) {
          f = a[mi];
          v = 1;
        }
        ni++;
      }
      mi++;
    }
    if (v) {
      cout << "YES" << endl << v << " " << f << endl;
    } else {
      cout << "NO" << endl;
    }
    t--;
  }
  return 0;
}
