for _ in range(int(input())):
    n1,n2=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    x=[]
    for i in a:
        if i in b:
            print("YES\n1",i)
            break
    else:
        print("NO")