def smallest_k(a ,b):
    distinct_b = set(b)
    for num in a:
        if num in distinct_b:
            return num
    return None

for _ in range(int(input())):
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    result = smallest_k(a, b)
    if not result:
        print("NO")
    else:
        print("YES")
        print("1 " + str(result))