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;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    int a[n], b[m];
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (int k = 0; k < m; k++) {
      scanf("%d", &b[k]);
    }
    int re1 = 0;
    int re2 = 0;
    vector<int> result;
    int size = 0;
    if (n >= m) {
      for (int i = re1; i < n && size != 1; i++) {
        for (int j = re2; j < m && size != 1; j++) {
          if (a[i] == b[j]) {
            size++;
            re1 = i + 1;
            re2 = j + 1;
            result.push_back(a[i]);
          }
        }
      }
    } else {
      for (int i = re1; i < m && size != 1; i++) {
        for (int j = re2; j < n && size != 1; j++) {
          if (b[i] == a[j]) {
            size++;
            re1 = i + 1;
            re2 = j + 1;
            result.push_back(a[i]);
          }
        }
      }
    }
    if (result.size() != 0) {
      cout << "YES" << endl;
      cout << result.size();
      cout << " ";
      cout << result[0];
      cout << "\n";
    } else {
      cout << "NO";
      cout << "\n";
    }
  }
  return 0;
}
