#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  char s[103];
  while (scanf("%d", &t) != EOF) {
    int k;
    for (int j = 0; j < t; j++) {
      scanf("%d", &k);
      scanf("%s", s);
      int best = 0, cur = 0;
      for (int i = 1; i < k; i++) {
        if (s[i] == 'P' && (s[i - 1] == 'A' || cur != 0))
          cur++;
        else if (s[i] == 'A' && cur != 0) {
          best = max(best, cur);
          cur = 0;
        }
      }
      best = max(best, cur);
      printf("%d\n", best);
    }
  }
  return 0;
}
