from collections import defaultdict 
t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    d=defaultdict(int)
    for i in range(n):
        d[a[i]]=1
    ans=0
    for i in range(m):
        if(d[b[i]]==1):
            ans=b[i]
            break
    if(ans!=0):
        print("YES")
        print(1,b[i])
    else:
        print("NO")