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