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