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