t = int(input())
for t1 in range(t):
    a, b = input().split()
    ar1 = list(map(int, input().split()))
    ar2 = list(map(int, input().split()))
    s1 = set(ar1)
    s2 = set(ar2)
    f = 0
    fd = int()
    for data in s1:
        if data in s2:
            f = 1
            fd = data
            break
    if(f==0):
        print("NO")
    else:
        print("YES")
        print(1,fd)        
            