# cook your dish here
t=int(input())
for _ in range(t):
    ip=list(map(int,input().split()))
    n=ip[0]
    m=ip[1]
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    f=0
    for i in l1:
        if i in l2:
            f=1
            print("YES")
            print("1",end=" ")
            print(i)
            break
    if f==0:
        print("NO")
        