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;
    cin >> n >> m;
    int a[n], b[m], c[m];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> b[i];
    }
    sort(a, a + n);
    sort(b, b + m);
    if (n == m == 1 && a[0] != b[0]) {
      cout << "NO" << endl;
    } else {
      int count = 0, flag = 0, b12 = 0, a12 = 0;
      sort(a, a + n);
      sort(b, b + m);
      int a1[n], b1[m];
      for (int i = 0; i < n; i++) {
        if (a[i] != a[i + 1]) {
          a1[i] = a[i];
          a12++;
        }
      }
      for (int i = 0; i < m; i++) {
        if (b[i] != b[i + 1]) {
          b1[i] = b[i];
          b12++;
        }
      }
      sort(b1, b1 + b12);
      sort(a1, a1 + a12);
      for (int i = 0; i < a12; i++) {
        for (int j = 0; j < b12; j++) {
          if (a1[i] == b1[j]) {
            c[flag] = a[i];
            count++;
            flag++;
          }
        }
      }
      if (count = 0) {
        cout << "NO" << endl;
      } else {
        if (c[0] == 1) {
          cout << "YES" << endl;
          for (int k = 0; k < flag; k++) {
            if (c[k] != 0 || c[k] != 1) {
              cout << c[k] << " ";
            }
          }
          cout << endl;
        } else {
          cout << "YES" << endl;
          cout << 1 << " ";
          for (int k = 0; k < flag; k++) {
            if (c[k] != 0 || c[k] != 1) {
              cout << c[k] << " ";
            }
          }
          cout << endl;
        }
      }
    }
  }
}
