#include <bits/stdc++.h>
using namespace std;
int power(int x, unsigned int y) {
  int temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
bool vowl(char c) {
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int k, i, maxi = 0;
    cin >> k;
    string str;
    cin >> str;
    for (i = 0; i < k; i++) {
      if (str[i] == 'A') {
        int count = 0;
        while (i + 1 < k && str[i + 1] == 'P') {
          count++;
          i++;
        }
        if (count > maxi) maxi = count;
      }
    }
    cout << maxi << "\n";
  }
}
