t = int(input())
for i in range(t):
    n, m = (int(i) for i in input().split())
    a = set(input().split())
    b = set(input().split())
    c = a.intersection(b)
    if (len(c) != 0):
        print ("YES")
        print ("1", c.pop())
    else:
        print ("NO")
