try:
    for t in range(int(input())):
        n,m = map(int,input().split())
        a = list(map(int,input().split()))
        b= list(map(int,input().split()))
        k = 0
        for i in range(0,m):
            if(b[i] in a):
                g = b[i]
                k = 1
                break
        if(k==0):
            print('NO')
        else:
            print('YES')
            print(k,' ',g)
except EOFError as e:
    pass
