#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
using namespace std;
int d[111][111][11];
int n;
int lol(int p1, int p2, int pt) {
if(p1 == p2 || p1 == -1 || p2 == n)
return 1;
if(d[p1][p2][pt] == 1)
return 1;
else if(d[p1][p2][pt] == 2)
return 2;
else if(d[p1][p2][pt] == -1)
return 2;
d[p1][p2][pt] = -1;
bool res = false;
if(pt != 0 && lol(p1+1, p2, 1) == 2)
res = true;
if(pt != 1 && lol(p1-1, p2, 0) == 2)
res = true;
if(pt != 2 && lol(p1, p2+1, 3) == 2)
res = true;
if(pt != 3 && lol(p1, p2-1, 2) == 2)
res = true;
if(res)
d[p1][p2][pt] = 1;
else
d[p1][p2][pt] = 2;
return d[p1][p2][pt];
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio();
int t;
cin >> t;
for(int g=0; g<t; g++) {
string s = "";
cin >> s;
int p1 = -1;
int p2;
for(int i=0; i<s.size(); i++) {
if(s[i] == 'P') {
if(p1 == -1)
p1 = i;
else
p2 = i;
}
}
n = s.size();
for(int i=0; i<n; i++)
for(int ii=0; ii<n; ii++)
for(int j=0; j<=4; j++) {
d[i][ii][j] = 0;
}
cout << lol(p1, p2, 4) << "\n";
}
}