#include <bits/stdc++.h>
using namespace std;
constexpr long long int MOD = 1000000007;
constexpr double EPS = 1e-8;
long long int N, M, K, H, W, L, R;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> K;
  while (K--) {
    cin >> N;
    string s;
    cin >> s;
    int bef = MOD;
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (s[i] == 'P')
        ans = max(ans, i - bef);
      else
        bef = i;
    }
    cout << ans << endl;
  }
}
