for i in range(int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    a=set(a)
    b=set(b)
    b=b.intersection(a)
    if len(b)>0:
        for i in b:
            print("YES")
            print(1,i)
            break
    else:
        print("NO")