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>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int A, B, C, D, E, H, W, M, K, L, R, N, X, Y, Z, num = 0, sum = 0,
                                                             flag = 0;
  string S, T;
  cin >> Z;
  while (Z--) {
    cin >> N >> M;
    vector<long long int> P(N, 0);
    vector<long long int> Q(M, 0);
    for (long long int i = 0; i < N; i++) cin >> P[i];
    for (long long int i = 0; i < M; i++) cin >> Q[i];
    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    num = -1;
    for (long long int i = 0; i < N; i++)
      for (long long int j = 0; j < M; j++)
        if (P[i] == Q[j]) num = P[i];
    if (num == -1)
      cout << "NO" << endl;
    else {
      cout << "YES" << endl;
      cout << num << endl;
    }
  }
}
