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