A professor may have stolen an idea I discussed with him: how to proceed?
I think it's very clear that you should talk with (B). You had previously discussed this idea with (B) so s/he knows that it was something that you had been considering. Furthermore, (B) also presumably knows the situation within the department better than you. Maybe (A) is known for doing things like this. Maybe the overlap isn't as serious as you think and (B) can reassure you that you can still do your thesis as you wanted to. No one here can decide whether either one of these is the case.

One word of advice: in talking with (B), present this situation as something that you are concerned about, but stay unemotional and stick to the facts: (B) knows that you were interested in this similar project, you discussed it with (A), and now another student is doing this project with (A). You do not need to connect the dots and accuse (A) directly of plagiarism or dishonest conduct in an initial conversation with (B). If this is a misunderstanding or miscommunication then doing so makes you seem aggressive and prone to jumping to conclusions. If (A) did something that is as blatantly dishonest as you have suggested, then that will be obvious to (B) as well.