inp = lambda:map(int,input().split())
for _ in range(int(input())):
    N,M = inp()
    seq1 = set(inp())
    seq2 = set(inp())
    res = list(seq1.intersection(seq2))
    if res:
        print("YES")
        print(1,res[0])
    else:
        print("NO")
