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 mx = 1e5 + 10;
const double PI = cos(-1.0);
map<int, int> a, b;
int n, m, t;
int main() {
  cin >> t;
  while (t--) {
    int x;
    cin >> n >> m;
    a.clear();
    b.clear();
    for (int i = 1; i <= n; i++) {
      cin >> x;
      a[x] = 1;
    }
    for (int i = 1; i <= m; i++) {
      cin >> x;
      b[x] = 1;
    }
    int f = 0;
    for (int i = 1; i <= 1000; i++) {
      if (a[i] && b[i]) {
        f = 1;
        printf("YES\n1 %d\n", i);
        break;
      }
    }
    if (f == 0) printf("NO\n");
  }
  return 0;
}
