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 t, n, m, a[1001], b[1001], c[1001], i, j, k, cnt, sum, num, mini;
int main() {
  cin >> t;
  for (j = 1; j <= t; j++) {
    cnt = 0;
    memset(a, 0, 1001 * sizeof(a[0]));
    memset(b, 0, 1001 * sizeof(b[0]));
    memset(c, 0, 1001 * sizeof(c[0]));
    cin >> n >> m;
    for (i = 1; i <= n; i++) {
      cin >> num;
      a[num]++;
    }
    for (i = 1; i <= m; i++) {
      cin >> num;
      b[num]++;
    }
    for (i = 1; i <= 1000; i++) {
      c[i] = min(a[i], b[i]);
      cnt = cnt + c[i];
    }
    if (cnt == 0) {
      cout << "NO\n";
      continue;
    }
    cout << "YES\n";
    cout << cnt << " ";
    for (i = 1; i <= 1000; i++) {
      for (k = 1; k <= c[i]; k++) {
        cout << i << " ";
      }
    }
    cout << "\n";
  }
}
