t = int(input())

def case():
    [n, m] = list(map(int, input().split()))
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))

    for i in a:
        for j in b:
            if i == j:
                return i

    return 0



for test_case in range(t):
    x = case()
    if x:
        print("YES")
        print("1 " + str(x))
    else:
        print("NO")
