# cook your dish here
for i in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    f=0
    b=list(map(int,input().split()))
    for k in a:
        if k in b:
            f=1
            print("YES")
            print(1,k)
            break
    if f==0:
        print("NO")