#include <bits/stdc++.h>
using namespace std;
int n;
bool dp[100][100][2][2];
bool dps[100][100][2][2];
bool f(int a, int b, int c, int d) {
if (dps[a][b][c][d]) return dp[a][b][c][d];
dps[a][b][c][d] = 1;
bool tor = 0;
if (a != n-1 && a+1 != b && !(c == 0 && d == 0) && !f(a+1, b, 0, 1)) tor = 1;
if (a != 0 && a-1 != b && !(c == 0 && d == 1) && !f(a-1, b, 0, 0)) tor = 1;
if (b != n-1 && b+1 != a && !(c == 1 && d == 0) && !f(a, b+1, 1, 1)) tor = 1;
if (b != n-1 && b-1 != a && !(c == 1 && d == 1) && !f(a, b-1, 1, 0)) tor = 1;
dp[a][b][c][d] = tor;
return tor;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for (int Ti = 0; Ti < T; ++Ti) {
string s;
cin >> s;
n = s.size();
bool af = 0;
int a, b;
for (int i = 0; i < n; ++i) {
if (s[i] == 'P') {
if (!af) a = i;
else b = i;
af = 1;
}
}
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j)
for (int c = 0; c < 2; ++c) for (int d = 0; d < 2; ++d) dps[i][j][c][d] = 0;
if (f(a, b, 0, 1) || f(a, b, 0, 0)) cout << "1\n";
else cout << "2\n";
}
}