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