t = int(input())
for _ in range(t):
    nm = input().split()
    n = int(nm[0])
    m = int(nm[1])

    first = list(map(int, input().split()))
    second = list(map(int, input().split()))

    second_track = {k : True for k in second}

    for item in first:
        if item in second_track:
            print('YES')
            print(1, item)
            break
    else:
        print('NO')
