for _ in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    x=set(a)
    y=set(b)
    c=x.intersection(y)
    d=list(c)
    if(len(d)==0):
        print("NO")
    else:
        print("YES")
        print(1,d[0])
