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