t=int(input())
for i in range(t):
    a,b=input().split()

    n=list(map(int,input().split()))
    m=list(map(int,input().split()))
    flag=0
    for j in n:
        if j in m:
            print('YES')
            print(1,j)
            flag=1
            break
    if(flag==0):
        print('NO')
    