use std::collections::{HashMap, VecDeque};
use std::io::BufRead;
fn solve(a: usize, b: usize, n: usize) -> usize {
let (a, b) = if a < b { (a, b) } else { (b, a) };
let rounds_till_left = a + b - 1;
let rounds_till_right = n - 1 - b + n - 2 - a;
assert_eq!(rounds_till_left % 2, rounds_till_right % 2);
if rounds_till_left % 2 == 1 || rounds_till_right % 2 == 1 {
1
} else {
2
}
}
fn main() {
let stdin = std::io::stdin();
let stdin = stdin.lock();
let mut lines = stdin.lines();
let t: usize = lines.next().unwrap().unwrap().parse().unwrap();
for _ in 0..t {
let l: String = lines.next().unwrap().unwrap();
let mut a = None;
let mut b = None;
for (i, c) in l.chars().enumerate() {
if c == 'P' {
if a == None {
a = Some(i);
} else {
b = Some(i);
}
}
}
println!("{}", solve(a.unwrap(), b.unwrap(), l.len()));
}
}
#[cfg(test)]
mod tests {
use super::*;
}