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