test = int(input())
for t in range(test):
    n,m = list(map(int,input().split(" ")))
    l1 = set(list(map(int,input().split(" "))))
    l2 = set(list(map(int,input().split(" "))))
    l1 = list(l1 & l2)
    if len(l1):
        print("YES")
        print(1,l1[0])
    else: print("NO")