#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100;
int n;
int result[N][N][5];
void rec(int a, int b, int c) {
if (result[a][b][c]) return;
result[a][b][c] = 2;
if (a > 0 && c != 1) rec(a-1, b, 0);
if (a + 1 != b && c != 0) rec(a+1, b, 1);
if (b < n - 1 && c != 3) rec(a, b+1, 2);
if (b - 1 != a && c != 2) rec(a, b-1, 3);
bool win = 0;
if (a > 0 && c != 1 && result[a-1][b][0] == -1) win = 1;
if (a+1 != b && c != 0 && result[a+1][b][1] == -1) win = 1;
if (b < n-1 && c != 3 && result[a][b+1][2] == -1) win = 1;
if (b-1 != a && c != 2 && result[a][b-1][3] == -1) win = 1;
if (win) result[a][b][c] = 1;
else result[a][b][c] = -1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
while (q--) {
for (int a = 0; a < N; ++a) {
for (int b = 0; b < N; ++b) {
for (int c = 0; c < 4; ++c) result[a][b][c] = 0;
}
}
string s;
cin >> s;
n = s.length();
result[0][1][3] = -1;
result[n-1][n][1] = -1;
int a = -1;
int b = -1;
for (int i = 0; i < n; ++i) {
if (a == -1 && s[i] == 'P') a = i;
else if (a != -1 && s[i] == 'P') b = i;
}
//for (int i = 0; i < 4; ++i) result[a][b][i] = 2;
rec(a, b, 4);
if (result[a][b][4] == -1) cout << "2\n";
else cout << "1\n";
}
}