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

#!/usr/bin/env python3
import os
from sys import stdin, stdout


def solve(tc):
    n, m = map(int, stdin.readline().split())
    sa = list(map(int, stdin.readline().split()))
    sb = list(map(int, stdin.readline().split()))

    mapA = [False for i in range(1001)]
    for i in range(n):
        mapA[sa[i]] = True

    for i in range(m):
        if mapA[sb[i]]:
            print("YES")
            print(1, sb[i])
            return

    print("NO")


tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1
