test = int(input())
for _ in range(test):
    n,m=map(int,input().split())
    f=0
    l=[int(n) for n in input().split()]
    z=[int(n) for n in input().split()]
    ans=l+z
    #print(ans)
    for i in z:
        if(i in l and i in z):
            print('YES')
            print(1,i)
            f=1
            break
    if(f==0):
        print('NO')
    