t=int(input())

while(t):
    q,r=input().split()
    x=input()
    y=input()
    a=[int(n) for n in x.split()]
    b=[int(m) for m in y.split()]
    flag=0
    for num in a:
        for num1 in b:
            if (num==num1) and (num>flag):
                flag=num

    if (flag!=0):
        print("YES")
        print("{} {}".format(1,flag))
    else:
        print("NO")
    t=t-1
