t = int(input())
for i in range(0,t):
    n,m = map(int,input().split())
    a = list(map(int,input().split()))
    b = list(map(int, input().split()))
    c=0
    for j in range(0,n):
        for k in range(0,m):
            if a[j]==b[k]:
                print("YES")
                print("1 ",a[j])
                c =1
                break
        if c==1:
            break

    if c==0:
        print("NO")
