Help needed in SPOJ question of Test CF25E

How can we solve the following problem using hashing ?
P.S. : I saw this question under practice section of string hashing on CP algorithm site

Someone please help…