#include <bits/stdc++.h>
using namespace std;
int t, k;
char s[200];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &k);
    scanf("%s", s);
    int len = strlen(s);
    int ans = 0;
    for (int i = 0; i < len; ++i) {
      if (s[i] == 'A') {
        int cnt = 0;
        while (s[i] == 'A') i++;
        int j;
        for (j = i; j < len; ++j)
          if (s[j] == 'P')
            cnt++;
          else
            break;
        ans = max(ans, cnt);
        i = j - 1;
      }
    }
    printf("%d\n", ans);
  }
}
