After human-beings arrived at Mars, they discovered the existence of aliens! What is…
- User
After human-beings arrived at Mars, they discovered the existence of aliens! What is more fascinating is that aliens had traffic lights just like we do. But traffic lights on Mars didn't work the way they do on Earth.
On the Earth, traffic lights follow a particular sequence, green yellow, red, green, yellow red and so on.
Humans got bored on space and decided to play a game. They recorded the sequence of colors on a traffic light from time 1 1 to time N N (inclusive), then created a sequence S S of length N N (G stands for Green, Y stands for Yellow, and R stands for Red). The value of S i S i determines the color of the traffic light at a time i i. Now humans want to extract a subsequence out of this sequence which should be valid according to traffic light rules on planet Earth (following the valid pattern), and have the maximum possible length. Help them achieve this task (green can be followed by green or yellow, yellow can be followed by yellow or red, and red can be followed by red or green).
input The first line consists of T T, the number of test cases. 1 ≤ T ≤ 100 1≤T≤100
First line of each test contains an Integer N N. 1 ≤ N ≤ 1 0 5 1≤N≤10 5
Second line of each test case contains string S S consisting of letters R, Y, G.
output The output consists of T T lines, each line containing the length of the longest valid subsequence.
examples Sample entry 1 2 7 YYRGRGG 7 RRRRGYY Plain text Sample output 1 6 7 Plain text In the first test case, the resulting subsequence would be: YYRRGG. c++
- Assistant