import collections
t=int(input())
for tc in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    A=collections.Counter(a)
    check=False
    for x in b:
        if(A[x]>0):
            print("YES")
            print("1 ",x)
            check=True
            break
    if(not check):
        print("NO")