Getting WA in my submission and im getting correct output in starters 9 in BUS

here is my submission link

Your code is looking for 5 queries in this testcase
5 1 4

It should print “INCONSISTENT” but your code only after getting 5th input it prints the solution

thanks i got it w=g must be replaced with w=g+1