for _ in range(int(input())):
    n,m=[int(c) for c in input().split()]
    a = set([int(c) for c in input().split()])
    b = {int(c) for c in input().split()}
    for i in a :
        if i in b:
            print("YES")
            print(1,i)
            break
    else:
        print("NO")