WA on BITMAP spoj question

Here’s my question http://www.spoj.com/problems/BITMAP/
and heres my solution
What I am doing here is BFS. First i am putting all white pixels in queue then the non white pixels just next to them and so on and to avoid repetition i am using a visited array.But still i am getting WA. Any hints on what is wrong with my solution?