t=int(input())
while t>0:
    n,m = list(map(int,input().split()))
    s1 = set(map(int, input().split()))
    s2 = set(map(int, input().split()))
    if len(s1.intersection(s2))==0:
        print('NO')
    else:
        print('YES')
        print(1,*list(s1.intersection(s2))[:1])
    t-=1