#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, ans = 0;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      int curr = 0;
      if (s[i] == 'A') {
        for (int j = i + 1; j < s.length() and s[j] == 'P'; j++) {
          curr++;
          i = j;
        }
      }
      ans = max(ans, curr);
    }
    cout << ans << endl;
  }
}
