WA IN SPOG PROBLEM D QUERY

PLEASE HELP ME FIND MISTAKE IN MY CODE.
PROBLEM LINK- SPOJ.com - Problem DQUERY
Source Code - Online Compiler and IDE >> C/C++, Java, PHP, Python, Perl and 70+ other compilers and interpreters - Ideone.com

Link expired, but I guess just making set, clearing it for every query, and then inserting elements and return size of set, would give AC.

I didn’t understand how it will work. Because I am storing the queries in the MultiSet.
Basically Mo’s Algorithm.
Source Code -
https://www.codechef.com/viewsolution/24851617