#sri
for _ in " "*int(input()):
    n,m=map(int,input().split(" "))
    la=[int(i) for i in input().split(" ")]
    lb=[int(i) for i in input().split(" ")]
    la.sort()
    lb.sort()
    for j in range(n):
        if la[j] in lb:
            print("YES")
            print("1 ",la[j])
            break
    else:
        print("NO")