test = int(input())
for t in range(test):
    l, r= map(int, input().split())
    lst1 = set(list(map(int, input().split())))
    lst2 = set(list(map(int, input().split())))
    k = list(set(lst1) & set(lst2))
    if len(k) != 0:
        print("YES")
        if len(k) > 1:
            print(1, end=" ")
        else:
            print(len(k), end=" ")
        for x in k:
            print(x)
            break
    else:
        print("NO")