#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
using namespace std;
using pi = pair<int,int>;
using lint = long long;
const int MAXN = 105;
int n;
char s[MAXN];
int memo[MAXN][MAXN][4];
int winner(int a, int b, int c){
if(memo[a][b][c] != -1) return memo[a][b][c];
int &r = memo[a][b][c];
r = 0;
if(a - 1 >= 0 && c != 1 && !winner(a-1, b, 0)){
return r = 1;
}
if(a + 1 < b && c != 0 && !winner(a+1, b, 1)){
return r = 1;
}
if(a < b - 1 && c != 2 && !winner(a, b - 1, 3)){
return r = 1;
}
if(b + 1 < n && c != 3 && !winner(a, b + 1, 2)){
return r = 1;
}
return r;
}
int main(){
int tc;
scanf("%d",&tc);
while(tc--){
scanf("%s",s);
n = strlen(s);
int a = -1, b = -1;
for(int i=0; i<n; ++i){
if(s[i] == 'P' && a == -1){
a = i;
}
if(s[i] == 'P' && a != -1){
b = i;
}
}
int c = 0;
for(int j=0; j<4; ++j) c |= winner(a, b, j);
printf("%d\n", 2 - c);
memset(memo, -1, sizeof(memo));
}
}