def intersection(lst1, lst2):
    return list(set(lst1) & set(lst2))


t = int(input())
while t != 0:
    n, m = map(int, input().split(' '))
    arr1 = list(map(int, input().split(' ')))
    arr2 = list(map(int, input().split(' ')))
    res = intersection(arr1, arr2)
    if len(res) > 0:
        print('YES')
        print(1, res[0])
    else:
        print('NO')
    t -= 1
