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