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 inf = 1e18;
long long mod = 1e9 + 7;
long long power(long long x, long long y, long long p) {
  long long res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long pwr(long long x, long long y) {
  long long res = 1;
  x = x;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y = y >> 1;
    x = (x * x);
  }
  return res;
}
long long modInverse(long long n, long long p) { return power(n, p - 2, p); }
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long fact(long long n) {
  if (n <= 1) return 1;
  return n * fact(n - 1);
}
long long nPr(long long n, long long r) { return fact(n) / fact(n - r); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t-- > 0) {
    long long n, m;
    cin >> n >> m;
    set<long long> s;
    string ans = "NO";
    for (int j = 0; j < n; j++) {
      long long x;
      cin >> x;
      s.insert(x);
    }
    int sz = s.size();
    long long out;
    for (int j = 0; j < m; j++) {
      long long x;
      cin >> x;
      if (ans == "NO") {
        s.insert(x);
      }
      if (s.size() == sz && ans == "NO") {
        ans = "YES";
        out = x;
      } else {
        sz = s.size();
      }
    }
    cout << (ans) << endl;
    if (ans == "YES") cout << (1) << " " << (out) << endl;
  }
  return 0;
}
