"Codeforces Round #658 (Div. 2)"
"A. Common Subsequence"
y=int(input())
for i in range(y):
    n,m=map(int,input().split())
    a=map(int,input().split())
    b=map(int,input().split())
    sa=set(a)
    sb=set(b)
    sc=set()
    sc=sa.intersection(sb)
    if len(sc)==0:
        print("NO")
    else:
        print("YES")
        print(1," ",sep="",end="")
        for j in sc:
            print(j)
            break    