#include <bits/stdc++.h>
using namespace std;
const long long INF = (1e12);
const long long mod = (998244353);
char str[(1000 + 10)];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    scanf("%s", str + 1);
    int ap = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (str[i] == 'P') {
        if (ap) {
          ans = max(ans, i - ap);
        }
      } else {
        ap = i;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
