import math
t = int(input())
rez = []

for i in range(t):
    A = input().split(" ")
    n = int(A[0])
    m = int(A[1])
    a = input().split(" ")
    b = input().split(" ")
    k = 0
    for j in range(n):
        a[j] = int(a[j])
    for j in range(m):
        b[j] = int(b[j])
        if b[j] in a:
            rez.append("YES")
            rez.append("1 "+str(b[j]))
            k = 1
            break
    if k != 1:
        rez.append("NO")




for i in range(len(rez)):
    print(rez[i])
