try:
    for _ in range(int(input())):
        n,m=map(int,input().split())
        a=set([int(i) for i in input().split()])
        b=set([int(i) for i in input().split()])
        c=list(a&b)
        if len(c)!=0:
            print("YES")
            print(1,c[0])
        else:
            print("NO")
        
except:
    pass

