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() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int a, b;
    cin >> a >> b;
    long long int n1[a], n2[b];
    for (long long int i = 0; i < a; i++) cin >> n1[i];
    for (long long int i = 0; i < b; i++) cin >> n2[i];
    sort(n1, n1 + a);
    sort(n2, n2 + b);
    long long int kp = min(a, b);
    long long int q, f = 0;
    for (long long int i = 0; i < kp; i++) {
      if (a == kp) {
        long long int pp = n1[i];
        for (long long int j = 0; j < b; j++) {
          if (pp == n2[j]) {
            f = 1;
            q = n1[i];
            i = kp + 1;
          }
        }
      } else {
        long long int pp = n2[i];
        for (long long int j = 0; j < a; j++) {
          if (pp == n1[j]) {
            f = 1;
            q = n2[i];
            i = kp + 1;
          }
        }
      }
    }
    if (f == 0)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      cout << "1 " << q << endl;
    }
  }
}
