n = int(input())
for i in range(n):
    s = input().split(' ')
    n = int(s[0])
    m = int(s[1])
    s1 = input().split(' ')
    s2 = input().split(' ')
    a = -1
    for j in range(n):
        for k in range(m):
            if s1[j] == s2[k]:
                a = int(s1[j])
                break
    if a != -1:
        print('YES')
        print('1 ' + str(a))
    else:
        print('NO')
