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()))
    
    a=list(set(a)&set(b))
    
    if len(a)==0:
        print("NO")
    else:
        print("YES")
        print(1,a[0])