for i in range(int(input())) :
    n, m = map(int, input().split())
    a = [int(num) for num in input().split()]
    b = [int(num) for num in input().split()]
    for i in a :
        if i in b :
            print('YES')
            print(1, i)
            break
    else :
        print('NO')