# cook your dish here
t=int(input())
for i in range(t):
    n,m=input().split()
    n=int(n)
    m=int(m)
    a=[int(i) for i in input().split(" ")]
    b=[int(i) for i in input().split(" ")]
    ans=int(0)
    for i in range(n):
        if(a[i] in b):
            ans=int(1)
            break
    if(ans==1):
        print("YES")
        print(1,a[i])
    if(ans==0):
        print("NO")
            