#include<bits/stdc++.h>//分析可知要求插入一个字母后ccpc的个数(插入一个后不可能多出两个答案串)
using namespace std;//尝试在没形成ccpc的未用字母中插入是否能形成新的ccpc
char str[1001000];
int len;
int book[1001000];
void check()
{
for(int i=1;i<=len;i++) str[i]=rand()%2==1?'P':'C';
str[len+1]='\0';
printf("%s\n",str+1);
}
int main()
{
//srand(time(0));
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&len);
scanf("%s",str+1);
int ans=0;
int flag=0;
for(int i=1;i<=len;i++)
{
if(i+3<=len&&str[i]=='C'&&str[i+1]=='C'&&str[i+2]=='P'&&str[i+3]=='C')
{
book[i]=book[i+1]=book[i+2]=book[i+3]=1;
ans++;
}
if(!book[i]&&!flag)//尝试在未用字母左右两段插入字母
{ //_l
if(i+2<=len&&str[i]=='C'&&str[i+1]=='P'&&str[i+2]=='C') {flag=1;}//1
if(i-1>=1&&i+1<=len&&str[i-1]=='C'&&str[i]=='P'&&str[i+1]=='C') {flag=1;} //2
if(i-2>=1&&str[i-2]=='C'&&str[i-1]=='C'&&str[i]=='C') {flag=1;}//3
if(i-3>=1&&str[i-3]=='C'&&str[i-2]=='C'&&str[i-1]=='P') {flag=1;}//4
//_r
if(i+3<=len&&str[i+1]=='C'&&str[i+2]=='P'&&str[i+3]=='C') {flag=1;}//1
if(i+2<=len&&str[i]=='C'&&str[i+1]=='P'&&str[i+2]=='C') {flag=1;}//2
if(i-1>=1&&i+1<=len&&str[i-1]=='C'&&str[i]=='C'&&str[i+1]=='C') {flag=1;} //3
if(i-2>=1&&str[i-2]=='C'&&str[i-1]=='C'&&str[i]=='P') {flag=1;}//4
}
book[i]=0;//用memset,,就tl惨了
}
printf("%d\n",ans+flag);
}
return 0;
}
11-06