t = int(input())
while t>0:
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    a.sort()
    b.sort()
    f = 0
    for i in a:
        if i in b:
            print("YES")
            print("1",i)
            f= 1
            break
    if f==0:
        print("NO")
    
    t = t - 1