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 namespace std;
int main() {
  int cases;
  cin >> cases;
  while (cases--) {
    int n, m;
    cin >> n >> m;
    int one[n], two[m];
    for (int i = 0; i < n; i++) {
      cin >> one[i];
    }
    for (int i = 0; i < m; i++) {
      cin >> two[i];
    }
    int arr1[1000], arr2[1000];
    for (int i = 0; i < 1000; i++) {
      arr1[i] = 0;
      arr2[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      arr1[one[i] - 1]++;
    }
    for (int i = 0; i < m; i++) {
      arr2[two[i] - 1]++;
    }
    int temp = 0;
    for (int i = 0; i < 1000; i++) {
      if (arr1[i] != 0 && arr2[i] != 0) {
        temp = i + 1;
        break;
      }
    }
    if (temp) {
      cout << "YES" << endl;
      cout << "1"
           << " " << temp << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}
