#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int it = 0; it < t; it++) {
    int ans = 0;
    int mx = 0;
    bool flg = 0;
    int x;
    cin >> x;
    for (int i = 0; i < x; i++) {
      char t;
      cin >> t;
      if (t == 'P' and flg == 1) {
        ans++;
        if (mx < ans) mx = ans;
      }
      if (t == 'A') {
        flg = 1;
        ans = 0;
      }
    }
    cout << mx << endl;
  }
  return 0;
}
