Hugphile Order- ACM ICPC Amritapuri Regionals 2014

Can anyone tell me the approach to solving this question or explain what has been done in given solutions?

Thanks.