t=int(input())
for _ in range(t):
    a,b=map(int,input().split())
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    s=set(l1)
    flag=0
    for i in l2:
        if(i in s):
            print('YES')
            print(1,i)
            flag=1
            break
    if(flag==0):
        print('NO')
