for _ in range(int(input())):
    n,m=[int(x) for x in input().split()]
    a=set([int(x) for x in input().split()])
    b=set([int(x) for x in input().split()])
    #print(a,b)
    found=False
    t=0
    for i in a:
        if i in b:
            found=True
            t=i
            break
    if found:
        print("YES")
        print("{} {}".format(1,t))
    else:
        print("NO")

