t=int(input())
while(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a.sort()
    b.sort()
    k=0
    for i in range(n):
        if a[i] in b:
            print("YES")
            print("1",a[i])
            k=1
            break
    if(k==0):
        print("NO")
    t=t-1