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;
using ll = long long int;
const ll mod = 1000000007;
const ll M = 1000000000000000000ll;
inline ll add(ll a, ll b) { return ((a % mod + b % mod) % mod); }
inline ll sub(ll a, ll b) { return ((a % mod - b % mod + mod) % mod); }
inline ll mult(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); }
inline ll power(ll n, ll x) {
  ll p = 1;
  while (x != 0) {
    if (x % 2 == 0) {
      n = mult(n, n);
      x = x / 2;
    }
    p = mult(p, n);
    x--;
  }
  return p;
}
inline ll recurmult(ll a, ll b) {
  ll r = 0;
  while (b) {
    if (b & 1) r = add(r, a);
    a = mult(2, a);
    b >>= 1;
  }
  return r % mod;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll t;
  cin >> t;
  while (t--) {
    ll n, m;
    cin >> n >> m;
    map<ll, ll> mp;
    ll x;
    for (ll i = 0; i < n; i++) {
      cin >> x;
      mp[x] = 1;
    }
    ll fl = 1;
    vector<ll> v;
    for (ll i = 0; i < m; i++) {
      cin >> x;
      v.push_back(x);
    }
    for (ll i = 0; i < m; i++) {
      if (mp[v[i]] == 1) {
        cout << "YES\n";
        fl = 0;
        cout << 1 << " " << x << "\n";
        break;
      }
    }
    if (fl == 1) cout << "NO\n";
  }
}
