for _ in range(int(input())):
    n,m=map(int,input().split())
    ar=set(map(int,input().split()))
    br=list(map(int,input().split()))
    flag=True
    for i in range(m):
        if(br[i] in ar):
            flag=False
            print('YES')
            print(1,br[i])
            break
    if(flag):
        print('NO')