for _ in range(int(input())):
    n,m=map(int,input().split())
    a=[int(x) for x in input().split()]
    b=[int(x) for x in input().split()]
    set_a=set(a)
    set_b=set(b)
    set_union=set_a & set_b
    for q in set_union:
        ans=q
        break
    if(len(set_union)==0):
        print('NO')
    else:
        print('YES')
        print('1',ans)