t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    ctr=0
    if n>m:
        l1=a
        l2=b
    else:
        l1=b
        l2=a
    for i in l1:
        if i in l2:
            print("YES")
            print(1,i)
            ctr=1
            break
    if ctr==0:
        print("NO")
