t = int(input())

for i in range(t):
    n,m = input().split(' ')
    a = input().split(' ')
    b = input().split(' ')
    v = 0

    for i in range(int(n)):
        if v == 1:
            break
        for j in range(int(m)):
            if int(a[i]) == int(b[j]):
                print('YES')
                print('1 ', a[i])
                v = 1
                break
    if v == 0:
        print('NO')
