Personal sense of humor showing through here. How does the brain deal with a straying thought? It cannot. It has no control of thoughts. Once they form, they are set out into the void. It can be as angry as it wants to be at that thought, but it ultimately cannot do anything about it.