for _ in range(int(input())):
    n,m=map(int,input().split())
    nlis=[int(i) for i in input().split()]
    mlis=[int(i) for i in input().split()]
    intersect=list(set(nlis).intersection(set(mlis)))
    if len(intersect)>0:
        print('YES')
        print(1,intersect[0])
    else:
        print('NO')