HACKERRANK: Sherlock and Queries (little updated)

https://www.hackerrank.com/challenges/sherlock-and-queries