test_case = int(input())
for _ in range(test_case):
    r1, r2 = map(int, input().split())
    array1 = list(map(int,input().split()))
    array2 = list(map(int,input().split()))
    flag = False
    for number in array1:
        if number in array2:
            flag = True
            print("YES")
            print('1', number)
            break
    if not flag:
        print('NO')
