There are 7 prisoners lining up in a queue.
Each of them is assigned a hat, black or white, randomly where each can see the hats in front of him but not behind.
Starting from the prisoner in the back, each of them says the word "black" or "white".
If 6 or more words match the hat colors of the prisoners who say it, all 7 prisoners are released.
If 2 or more words do not match the hat colors, they will all be killed.
Is there a way to guarantee their release?