def main():
    test=int(input())
    for _ in range(test):
        n,m=map(int,input().split())
        arr1=list(map(int,input().split()))
        arr2=list(map(int,input().split()))
        l=[]
        for i in arr1:
            for j in arr2:
                if i==j:
                    l.append(i)
        if len(l)>0:
            print('YES')
            print(1,l[0])
        else:
            print('NO')
main()