#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define X first
#define Y second
const ll N = 1e2 + 5;
const ll INF = 1e18;
const ll M = 1e5 + 5;
unordered_map<ll, bool> ma;
ll ha(ll a, ll b) {
if(a > b) swap(a, b);
return N*a + b;
}
bool z[M];
int main() {
int t;
cin >> t;
while(t > 0) {
--t;
string s;
cin >> s;
int n = s.size();
int a = -1; int b = -1;
for(int i = 0; i < n; ++i) {
if(s[i] == 'P') {
if(a == -1) {
a = i;
} else {
b = i;
break;
}
}
}
if((a+b)%2 == 1) {
cout << 2 << "\n";
} else {
cout << 1 << "\n";
}
}
}