from collections import Counter
for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    da=Counter(a)
    db=Counter(b)
    f=0
    ans=0
    if min(n,m)==n:
        d1=da
        d2=db
    else:
        d1=db
        d2=da
    for i in d1:
        if d2[i]>=1:
            f=1
            ans=i
            break
    if f==1:
        print("YES")
        print(f'1 {ans}')
    else:
        print("NO")