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;
const long long N = 1e6 + 1;
set<long long> o;
map<long long, long long> mp, pm;
map<char, long long> hs;
vector<long long> v, vc, oreder1, inoreder, posoreder, ve, vv, vd;
deque<char> p, pe;
deque<string> ts, ss, stoi, rs;
deque<double> sd, ds;
string g, s, w, h, s1;
char z, u = 'a';
bool re, rt;
deque<int> e;
map<pair<long long, long long>, long long> aw, wa;
long long cnt, ans, TT, n, a, b, c, q, m, t, d, temp, mx = 0, mn = 0, rem, sum,
                                                      tt = 1e32;
int main() {
  ios_base::sync_with_stdio(0);
  srand(time(NULL));
  cin >> n;
  for (long long i = 0; i < n; i++) {
    m = 10000;
    cnt = 0;
    o.clear();
    cin >> a >> b;
    for (long long j = 0; j < a; j++) {
      cin >> c;
      o.insert(c);
    }
    for (long long j = 0; j < b; j++) {
      cin >> c;
      if (o.count(c) == 1) cnt = 1;
      ans = min(m, c);
    }
    if (cnt == 1)
      cout << "YES" << endl << 1 << " " << m << endl;
    else
      cout << "NO" << endl;
  }
}
