from collections import Counter
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()))
    c1=Counter(a)
    c2=Counter(b)
    c=c1&c2
    if(bool(c)):
        print("YES")
        print("1",c.most_common(1)[0][0])
    else:
        print("NO")