from collections import defaultdict
for _ in range(int(input())):
    n,m=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    d1=defaultdict(int)
    d2=defaultdict(int)
    for i in l1:
        d1[i]+=1
    for i in l2:
        d2[i]+=1
    f=0
    for i in d1:
        if i in d2:
            f=1
            print("YES")
            print(1,i)
            break
    if f==0:
        print("NO")