t=int(input())
for _ in range(t):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    if len(a)<len(b):
        A,B=a,b
    else:
        A,B=b,a
        n,m=m,n

    value=0
    flag="NO"
    for i in A:
        if i in B:
            flag="YES"
            value=i
            break
    print(flag)
    if flag=="YES":
        print(1,value)