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;
long long int find_ans(long long int x, long long int k, long long int a[],
                       long long int n) {
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) ans += pow(abs(a[i] - x), k);
  return ans;
}
int32_t main() {
  long long int tt;
  cin >> tt;
  while (tt--) {
    long long int n, m;
    cin >> n >> m;
    long long int a[n], b[m];
    for (long long int i = 0; i < n; i++) cin >> a[i];
    for (long long int i = 0; i < m; i++) cin >> b[i];
    long long int ans = -1;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < m; j++) {
        if (a[i] == b[j]) {
          ans = a[i];
          break;
        }
      }
    }
    if (ans == -1) {
      cout << "NO";
    } else {
      cout << "YES\n";
      cout << "1 " << ans;
    }
    cout << "\n";
  }
  return 0;
}
