#list(map(int,input().split()))
for _ in range(int(input())):
    n,m=list(map(int,input().split()))
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    flag=1
    for i in b:
        if(i in a):
            print("YES")
            print(1,i)
            flag=0
            break
    if(flag==1):
        print("NO")