n = int(input())
a1 = []
for i in range(n):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    d = list(map(int, input().split()))
    f = False
    for k in range(0, len(c)):
        if c[k] in d:
            a1.append(['YES', 1, c[k]])
            f = True
            break
    if f == False:
        a1.append(['NO'])
for i in range(0, len(a1)):
    if a1[i][0] == 'YES':
        print('YES')
        print(a1[i][1], a1[i][2])
    else:
        print('NO')
