#include <bits/stdc++.h>
using namespace std;
int t, k;
char s[110];
int main() {
  cin >> t;
  while (t--) {
    cin >> k;
    cin >> (s + 1);
    int ans = 0;
    for (int i = 1; i <= k; i++) {
      if (s[i] == 'A') {
        for (int j = i + 1; j <= k && s[j] == 'P'; j++) {
          ans = max(ans, j - i);
        }
      }
    }
    cout << ans << endl;
    memset(s, 0, sizeof(s));
  }
  return 0;
}
