t = int(input())

for i in range(t):
    n,m = map(int,input().split(' '))
    a = list(map(int,input().split(' ')))
    b = list(map(int,input().split(' ')))
    flag = False
    
    for i in a:
        if i in b:
            flag = True
            res = i
            break
    if flag:
        print('YES')
        print(1,res)
    else:
        print('NO')