t = int(input())
for _ in range(t):
    n,m = list(map(int , input().strip().split()))
    array1 = list(map(int , input().strip().split()))
    array2 = list(map(int , input().strip().split()))
    set1 = set(array1)
    set2 = set(array2)
    common = list(set1.intersection(set2))
    if len(common) == 0:
        print("NO")
    else:
        print("YES")
        print(1,end=' ') 
        print(common[0])


