t = int(input())
cnt = 0
while (cnt < t):
    cnt += 1
    n, m = [int(i) for i in input().split()]
    a = set(int(i) for i in input().split())
    b = set(int(i) for i in input().split())
    a &= b
    if a:
        print('YES')
        print(1, end = ' ')
        for elem in a:
            print(elem)
            break
    else:
        print('NO')
    