t = int(input()) 
for _ in range (t): 
    n,m = map(int, input().split()) 
    A = set(map(int, input().split())) 
    B = set(map(int, input().split())) 
    C = A.intersection(B) 
    if len(C) == 0:
        print ("NO")
        continue

    print ("YES")
    print (1, C.pop())  