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;
void Thai_Jase() {
  long long n, m, r = INT_MAX;
  cin >> n >> m;
  long long a[n], b[m], *A = new long long[1001], *B = new long long[1001];
  memset(A, 0, 1001);
  memset(B, 0, 1001);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    ++A[a[i]];
  }
  for (long long i = 0; i < m; i++) {
    cin >> b[i];
    ++B[b[i]];
  }
  for (long long i = 1; i < 1001; i++) {
    if (A[i] && B[i]) r = min(r, min(A[i], B[i]));
  }
  if (r == INT_MAX) {
    cout << "NO" << endl;
    return;
  }
  for (long long i = 1; i < 1001; i++) {
    if (A[i] && B[i]) {
      cout << "YES" << endl;
      cout << r << " " << i << endl;
      return;
    }
  }
  cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int ts;
  cin >> ts;
  while (ts--) {
    Thai_Jase();
  }
  return 0;
}
