I = lambda: set(map(int, input().split()))
J = lambda: int(input())
K = lambda: list(map(int, input().split()))
for _ in range(int(input())):
    n, m = K()
    A = I()
    B = I()
    C = A & B
    print("YES\n1", C.pop())if C else print("NO")
    
