for TEST in range(int(input())):
    n, m = map(int,input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    S = set(A)&set(B)
    if S: print("YES"); print(1, next(iter(S)))
    else: print("NO")