t=int(input())
for i in range(0,t):
    N,M=map(int,input().split())
    list1=list(map(int,input().split()))
    list2=list(map(int,input().split()))
    mp=set()
    c=0
    e=0
    for i in range(0,N):
        mp.add(list1[i])
    for i in range(0,M):
        if list2[i] in mp:
            c=c+1
            e=list2[i]
            break
    if c==0:
        print("NO")
    else:
        print("YES")
        print(c,end=" ")
        print(e)             
