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 code() {
  long long int n, m;
  cin >> n >> m;
  std::vector<long long int> v(n);
  std::vector<long long int> z(m);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> z[i];
  }
  long long int ans, count = 0;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (v[i] == z[j]) {
        count++;
        ans = v[i];
      }
      if (count == 1) break;
    }
  }
  if (count == 1) {
    cout << "YES"
         << "\n";
    cout << 1 << " " << ans << "\n";
  } else
    cout << "NO"
         << "\n";
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    code();
  }
  return 0;
}
