#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int k;
    cin >> k;
    string s;
    cin >> s;
    int cont = 0;
    int maxc = 0;
    int b = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == 'A') {
        b = 1;
        if (cont > maxc) {
          maxc = cont;
        }
        cont = 0;
      }
      if (b == 1) {
        if (s[i] == 'P') {
          cont++;
        }
      }
    }
    if (cont > maxc) {
      maxc = cont;
    }
    cout << maxc << "\n";
  }
  return 0;
}
