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