t = int(input())
for x in range(t):
    l1 = [int(x) for x in input().split()]
    n,m = l1[0],l1[1]
    l2 = set([int(x) for x in input().split()])
    l3 = set([int(x) for x in input().split()])
    done=0
    for x in l2:
        if x in l3:
            done=1
            print("YES")
            print(1,x)
            break
    if not done:
        print("NO")
