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;
struct fast_mod {
  int mod = 1e9 + 7;
  template <typename T>
  bool isEven(T x) {
    return !(x & 1);
  }
  template <typename T>
  bool isOdd(T x) {
    return x & 1;
  }
  int addmod(int x, int y, int m) { return ((x % m) + (y % m)) % m; }
  int multmod(int x, int y, int m) { return ((x % m) * (y % m)) % m; }
  int submod(int x, int y, int m) { return ((x % m) - (y % m)) % m; }
  int regmod(int x) { return x % mod; }
};
struct bintree {
  struct bintree *left;
  struct bintree *right;
  int val;
  bintree(int v) {
    val = v;
    left = NULL;
    right = NULL;
  }
};
struct segtree {
  struct segtree *lChild;
  struct segtree *rChild;
  long long sum;
  int leftmost, rightmost;
  segtree(int left, int right, vector<int> &arr) {
    leftmost = left;
    rightmost = right;
    if (left == right) {
      sum = arr[left];
    } else {
      int mid = (left + right) / 2;
      lChild = new segtree(left, mid, arr);
      rChild = new segtree(mid + 1, right, arr);
      this->update();
    }
  }
  void update() {
    if (leftmost == rightmost) return;
    sum = lChild->sum + rChild->sum;
  }
  void pointUpdate(int index, int newVal) {
    if (leftmost == rightmost) {
      sum = newVal;
      return;
    }
    if (index <= lChild->rightmost)
      lChild->pointUpdate(index, newVal);
    else
      rChild->pointUpdate(index, newVal);
    update();
  }
  long long query(int left, int right) {
    if (left > rightmost || right < leftmost) {
      return 0LL;
    } else if (left <= leftmost && right >= rightmost)
      return sum;
    return lChild->query(left, right) + rChild->query(left, right);
  }
};
class Graph {
  int V;
  list<int> *adj;

 public:
  Graph(int V);
  void addEdge(int u, int v);
};
Graph::Graph(int V) {
  this->V = V;
  adj = new list<int>[V];
}
template <typename T>
bool binsearch(vector<T> &nums, int target) {
  int left = 0, right = nums.size() - 1;
  while (left <= right) {
    int mid = (left + right) / 2;
    if (nums[mid] == target)
      return true;
    else if (nums[mid] < target)
      left = mid + 1;
    else
      right = mid - 1;
  }
  return false;
}
namespace number_theory {
vector<int> sieve(int n) {
  bool prime[15000105];
  for (int i = 0; i < n; i++) prime[i] = 1;
  for (int i = 2; i <= n; i++)
    if (prime[i])
      for (int j = i * i; j <= n; j += i) prime[j] = 0;
  vector<int> ans;
  for (int i = 2; i <= n; i++)
    if (prime[i]) ans.push_back(i);
  return ans;
}
vector<long long> pfactors(int n) {
  vector<long long> pf;
  for (long long i = 2; i < n / 2; i++) {
    int c = 0;
    while (n % i == 0) {
      c++;
      n /= i;
    }
    if (c) pf.push_back(i);
  }
  return pf;
}
bool isPrime(int n) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (n == 3) return true;
  if (n % 3 == 0 || n % 2 == 0) return false;
  for (int i = 5; i * i <= n; i += 6) {
    if (n % i == 0 || n % (i + 2) == 0) return false;
  }
  return true;
}
}  // namespace number_theory
void solve() {
  int test_case;
  cin >> test_case;
  while (test_case--) {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    set<int> second;
    for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      second.insert(a);
    }
    bool ok = 1;
    for (int i = 0; i < m; i++) {
      int a;
      cin >> a;
      if (second.count(a)) {
        ok = 0;
        cout << "YES\n";
        cout << 1 << " " << a << '\n';
        ;
        break;
      }
    }
    if (ok) cout << "NO" << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ;
  solve();
}
