for i in range(int(input())):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    d=list(map(int,input().split()))
    e=True
    for j in c:
        if j in d:
            print("YES")
            print(1,j)
            e=False
            break
    if e==True:
        print("NO")