#!/usr/bin/env python
seen_states = []
def solve(n, first, second, prev_move, turn):
#print n, first, second, prev_move, turn
if (first, second, prev_move, turn) in seen_states:
return turn
seen_states.append((first, second, prev_move, turn))
if first > 0 and prev_move != 2:
winner = solve(n, first - 1, second, 1, not turn)
if winner == turn:
return winner
if first + 1 != second and prev_move != 1:
winner = solve(n, first + 1, second, 2, not turn)
if winner == turn:
return winner
if second + 1 < n and prev_move != 3:
winner = solve(n, first, second + 1, 4, not turn)
if winner == turn:
return winner
if second - 1 != first and prev_move != 4:
winner = solve(n, first, second - 1, 3, not turn)
if winner == turn:
return winner
return not turn
#for n in range(2, 16):
# for l in range(n - 1):
# for r in range(l + 1, n):
# seen_states = []
# sol = 2 if solve(n, l, r, None, False) else 1
# if sol != (r - l) % 2 + 1:
# print n, l, r, sol
#
#raise Exception('done')
t = int(raw_input())
for x in range(t):
seen_states = []
thing = raw_input()
first = thing.find('P')
second = first + 1 + thing[first+1:].find('P')
#print 2 if solve(len(thing), first, second, None, False) else 1
print (second - first) % 2 + 1