n=int(input())
for _ in range(n):
    n,m=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    k=0
    for i in range(n):
        if l1[i] in l2:
            print("YES")
            print(1,l1[i])
            k=1
            break
    if k==0:
        print("NO")
    
        
            