t=int(input())
for tt in range(t):
    n,m=[int(x) for x in input().split(' ')]
    a=[int(x) for x in input().split(' ')]
    b=[int(x) for x in input().split(' ')]
    a.sort()
    b.sort()
    all_members_a=set(a)
    all_members_b=set(b)
    fl=1
    for mem in all_members_a:
        if(mem in all_members_b):
            print('YES')
            print(1,mem)
            fl=0
            break
    if(fl):
        print('NO')
