Help needed in RGB code

https://www.codechef.com/viewsolution/55197943
what is wrong in my logic?getting wrong ans.

Hey, this Video Editorial might be of help
RGBCONST

There must be one red and one green in between two blues.
in this testcase -

1
3 3 3
BRRRGGGBB
1 2
2 3
2 4
2 5
2 6
2 7
3 8
4 9

As you can see you have connected
1 → 2 → 4 → 9
B → R → R → B
Both 2 and 4 are red.
which is incorrect.

thanks:)