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