t = int(input())
a = []
b = []
for _ in range(t):
    len_a_b = input()
    a.append([int(x) for x in input().split()])
    b.append([int(x) for x in input().split()])
for i in range(t):
    a_set = set(a[i])
    b_set = set(b[i])

    c_set = a_set.intersection(b_set)
    if(len(c_set)):
        print('YES')
        print(1 ,end=' ')
        print(c_set.pop())
    else:
        print('NO')