t=int(input())
for _ in range(0,t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))    
    b=list(map(int,input().split()))
    flag=0
    for i in range(0,len(a)):
        if a[i] in b:
            flag=1
            break
    if flag==1:
        print("YES")
        print(1,a[i])
    else:
        print("NO")
