#include
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while(t–){
int d,p,cnt=0,pro=0,flag=0;
cin >> d;
string s;
cin >> s;
for(int j=0;j<d;j++){
if(s[j]==‘P’){cnt++;}
}
if(cnt100/d>=75){cout<<pro<<endl;}
else{
for(int i=2; i<d-2; i++){
if(cnt100/d<75){
if((s[i-2]==‘P’||s[i-1]==‘P’)&&(s[i+1]==‘P’||s[i+2]==‘P’)){s[i]=‘P’;cnt++;pro++;}
}
else{flag=1;break;}
}
if(cnt*100/d>=75){flag=1;}
if(flag){cout<<pro<<endl;}
else{cout<<-1<<endl;}
}
}
return 0;
}