cases = int(input())
for t in range(cases):
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    b = list(map(int,input().split()))
    f = 0
    for i in range(n):
        for j in range(m):
            if a[i]==b[j]:
                output = i+1
                f = 1
                break
        if f==1:
            break
    if f==0:
        print("NO")
    else:
        print("YES")
        print(1,a[output-1])