t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    N=list(map(int,input().split()))
    M=list(map(int,input().split()))
    aj=0
    for j in range(n):
        for k in range(m):
            if(N[j]==M[k]):
                c=j+0
                aj=37
    if(aj==0):
        print("NO")
    else:
        print("YES")
        print(1,N[c])
