for i in  range(int(input())):
    l,m=map(int,input().split())
    a=set(map(int,input().split()))
    b = set(map(int, input().split()))
    z=a.intersection(b)
    if z:
        print("YES")
        print(1,list(z)[0])
    else:
        print("NO")