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;
struct s_ix {
  long long t, ix;
};
bool operator<(s_ix aa, s_ix bb) { return aa.t < bb.t; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, m, a[1200], b[1200];
    set<long long> ss;
    cin >> n >> m;
    for (int j = 0; j < n; j++) cin >> a[j];
    for (int j = 0; j < m; j++) cin >> b[j];
    int err = 0;
    long long ans;
    if (n > m) {
      for (int j = 0; j < n; j++) {
        ss.insert(a[j]);
      }
      for (int j = 0; j < m; j++) {
        if (ss.count(b[j]) > 0) {
          err = 1;
          ans = b[j];
          break;
        }
      }
    } else {
      for (int j = 0; j < m; j++) {
        ss.insert(b[j]);
      }
      for (int j = 0; j < n; j++) {
        if (ss.count(a[j]) > 0) {
          err = 1;
          ans = b[j];
          break;
        }
      }
    }
    if (err == 1) {
      cout << "YES" << endl;
      cout << 1 << " " << ans << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
