num_cases = int(input())
for case in range(num_cases):
    arr_lengths = [int(num) for num in input().split()]
    arr_a = [int(num) for num in input().split()]
    arr_b = [int(num) for num in input().split()]
    sub = False
    num1 = -1
    for num in arr_a:
        if num in arr_b:
            sub = True
            num1 = num
            break
    if sub:
        print('YES')
        print(1, num1)
    else:
        print("NO")