t = int(input())
for test_cases in range(t):
    m,n=input().split(' ')
    m_list = input().split(' ')
    n_list = input().split(' ')
    
    common_list = set(m_list).intersection(n_list)
    if len(common_list)>0:
        print('YES')
        print(1,list(common_list)[0])
    else:
        print('NO')