for q in range(int(input())):
    n, k = map(int, input().split())
    A = set(map(int, input().split()))
    B = set(map(int, input().split()))
    x = A&B
    if len(x) > 0:
        print("YES")
        print(1, list(A&B)[0])
    else:
        print("NO")