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>
int main(void) {
  int a1[1000], a2[1000], t = 0, i, num = 0, min = 0, s1, s2, j, element = 0;
  scanf("%d", &i);
  for (; i > 0; i--) {
    scanf("%d", &s1);
    scanf("%d", &s2);
    for (j = 0; j < s1; j++) scanf("%d", &a1[j]);
    for (j = 0; j < s2; j++) scanf("%d", &a2[j]);
    if (s1 >= s2) {
      for (j = 0; j < s1; j++) {
        for (t = 0; t < s2; t++) {
          if (a1[j] == a2[t]) num++;
        }
        if (min == 0 || min > num) {
          min = num;
          element = a1[j];
        }
        num = 0;
      }
    }
    if (s2 > s1) {
      for (j = 0; j < s2; j++) {
        for (t = 0; t < s1; t++) {
          if (a1[t] == a2[j]) num++;
        }
        if (min == 0 || min > num) {
          min = num;
          element = a1[t];
        }
        num = 0;
      }
    }
    if (!min)
      printf("NO\n");
    else {
      printf("YES\n");
      printf("1 %d", element);
    }
    min = 0;
  }
  return 0;
}
