for _ in [0]*int(input()):

    x,y=map(int,input().split())
    a,b=set(map(int,input().split())),set(map(int,input().split()))
    if len(list(a.intersection(b)))==0 :
        print('NO')
    else: 
        print('YES',1,list(a.intersection(b))[0],sep=" ")