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;
  cin >> t;
  while (t--) {
    int n, m, i = 0;
    cin >> n >> m;
    int arn[n], arm[m];
    while (i < n) {
      cin >> arn[i];
      i++;
    }
    i = 0;
    while (i < m) {
      cin >> arm[i];
      i++;
    }
    sort(arn, arn + n);
    sort(arm, arm + m);
    i = 0;
    int j = 0;
    if (arn[i] < arm[j]) {
    x:
      while (arn[i] < arm[j] && i < n) {
        i++;
      }
      if (arn[i] == arm[j]) {
        cout << "YES" << endl;
        cout << "1 " << arn[i] << endl;
      } else if (j < m) {
        j++;
        goto x;
      }
      if (i == n || j == m) {
        cout << "NO" << endl;
      }
    } else if (arn[i] > arm[j]) {
      i = 0, j = 0;
    y:
      while (arn[i] > arm[j] && j < m) {
        j++;
      }
      if (arn[i] == arm[j]) {
        cout << "YES" << endl;
        cout << "1 " << arn[i] << endl;
      } else if (i < n) {
        i++;
        goto y;
      }
      if (i == n || j == m) {
        cout << "NO" << endl;
      }
    } else {
      cout << "YES" << endl;
      cout << "1 " << arn[i] << endl;
    }
  }
  return 0;
}
