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;
const int INF = 0x3f3f3f3f;
template <typename T>
void read(T &first) {
  first = 0;
  char ch = getchar();
  long long f = 1;
  while (!isdigit(ch)) {
    if (ch == '-') f *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    first = first * 10 + ch - 48;
    ch = getchar();
  }
  first *= f;
}
int first[2000];
int second[2000];
int z[2000];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    int m;
    cin >> n >> m;
    memset(z, 0, sizeof(z));
    int a;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a);
      z[a]++;
    }
    for (int i = 1; i <= m; i++) {
      scanf("%d", &a);
      z[a]++;
    }
    int judge = 0;
    for (int i = 0; i <= 2000; i++) {
      if (z[i] > 1) {
        judge = i;
      }
    }
    if (judge == 0)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      cout << 1 << " " << judge << endl;
    }
  }
  return 0;
}
