Exists or not problem in hackerblocks

I am doing the query part in O(q) still getting time limit exceeding in test case 2.My code is written in

Hi @Bhawna, why are you taking q as input ??

Hi
Your code is not printing anything
Please comment your code or explain it here

this is very lame but i found the solution basically we have to use first count function to check whether element is present or not but main part is we have to use array to store element and use array to store queries then use that array to find solution.