t=int(input())
for t1 in range(t):
    n,m=input().split()
    #print(n,m)
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    for i in a:
        if i in b:
            print("YES")
            print(1, i)
            break
    else:
        print("NO")
