Can't Understand what case i am missing

I am trying to solve the Not All Flavors(NOTALLFL) problem, I considered all cases in my code but after submitting the 4 cases give me results

  1. WA
  2. AC
  3. WA
  4. AC

HERE IS MY SOLUTION

please tell me what kind of test case am i getting wrong???

Consider the test input:

1
9 2
1 2 2 1 2 2 2 2 2

Thank you…Got it right, (My Solution), plz look at my solution and tell if there is some better technique to do it, it would be very helpful …