for z in range(int(input())):
    n,m=list(map(int,input().split()))

    a=list(map(int,input().split()))
    b=list(map(int,input().split()))

    Set_a=set(a)
    Set_b=set(b)

    ans=0

    flag=False

    for x in Set_a:
        if x in Set_b:
            flag=True
            ans=x
            break

    if flag:
        print("YES")
        print(1,ans)
    else:
        print("NO")