for _ in range(int(input())):
    n,m=map(int,input().split())
    l=list(map(int,input().split()))
    k=list(map(int,input().split()))
    f=0
    for i in l:
        for j in k:
            if i==j:
                print("YES")
                f=1
                print(1,i)
                break
        if f==1:
            break
    if f==0:
        print("NO")