for _ in range(int(input())):
    n,m=map(int,input().split())
    a1=[int(i) for i in input().split()]
    a2=[int(i) for i in input().split()]
    a=None
    if n<m:
        for i in a1:
            if i in a2:
                a=i
                break
    else:
        for i in a2:
            if i in a1:
                a=i
                break
    if a==None:
        print("NO")
    else:
        print("YES")
        print(1,a)


      