Getting TLE after doing a BFS and implementing a trie on H1

Problem : http://www.codechef.com/problems/H1

This is my implementation
http://www.codechef.com/viewplaintext/2707780

I am implementing a BFS to check all reachable states and mapping the states reached in a trie.
But I am unable to get it to run within the time limits. I will be grateful if someone can throw some light on how to improve my code.

http://pastebin.com/C5ssqB1a
here is my code in pastebin for better readability