for _ in range(int(input())):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    flag=0
    for x in a:
        if x in b:
            flag=1
            z=x
            break
    if flag==0:
        print("NO")
    else:
        print("YES")
        print(1,z)