#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][5];
int Rec(int a, int b, int c){
if(memo[a][b][c] != -1) return memo[a][b][c];
int &r = memo[a][b][c];
r = 1;
if(a - 1 >= 0 && c != 0 && !Rec(a-1, b, 1)) return r;
if(a + 1 < b && c != 1 && !Rec(a+1, b, 0)) return r;
if(a < b - 1 && c != 2 && !Rec(a, b-1, 3)) return r;
if(b + 1 < n && c != 3 && !Rec(a, b+1, 2)) return r;
return r = 0;
}
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'){
if(a == -1) a = i;
else b = i;
}
}
printf("%d\n", 2 - Rec(a, b, 4));
memset(memo, -1, sizeof(memo));
}
}